Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set explicit screen when spawning own xvfb #6199

Merged
merged 3 commits into from
Jan 22, 2020
Merged

fix: set explicit screen when spawning own xvfb #6199

merged 3 commits into from
Jan 22, 2020

Conversation

isnotgood
Copy link
Contributor

@isnotgood isnotgood commented Jan 20, 2020

User facing changelog

Fixes cypress verify crash on some systems caused by not defined -screen.

Additional details

cypress verify crashes in a docker image with this environment:

root@6c2f9da07ecd:/app# uname -a 
Linux 6c2f9da07ecd 4.9.184-linuxkit #1 SMP Tue Jul 2 22:58:16 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
root@6c2f9da07ecd:/app# cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.3 LTS"
root@6c2f9da07ecd:/app# apt list xvfb 
Listing... Done
xvfb/bionic-updates,now 2:1.19.6-1ubuntu4.3 amd64 [installed]
N: There are 2 additional versions. Please use the '-a' switch to see them.
root@6c2f9da07ecd:/app# node -v 
v10.14.2
root@6c2f9da07ecd:/app# ./node_modules/.bin/cypress -v 
Cypress package version: 3.8.2
Cypress binary version: 3.8.2
root@6c2f9da07ecd:/app# file /root/.cache/Cypress/3.8.2/Cypress/Cypress 
/root/.cache/Cypress/3.8.2/Cypress/Cypress: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/l, for GNU/Linux 3.2.0, BuildID[sha1]=5b4fa88bff30493405377c54ef4308de9e5db705, stripped

When I run it with ELECTRON_ENABLE_STACK_DUMPING I get this:

root@6c2f9da07ecd:/app# ELECTRON_ENABLE_STACK_DUMPING=1 ./node_modules/.bin/cypress verify 
It looks like this is your first time using Cypress: 3.8.2

 ✖  Verifying Cypress can run /root/.cache/Cypress/3.8.2/Cypress
   → Cypress Version: 3.8.2
Cypress failed to start.

This is usually caused by a missing library or dependency.

The error below should indicate which dependency is missing.

https://on.cypress.io/required-dependencies

If you are using Docker, we provide containers with all required dependencies installed.

----------

Received signal 11 SEGV_MAPERR fffff4109b7ba15a
#0 0x55720269a3d9 (/root/.cache/Cypress/3.8.2/Cypress/Cypress+0x35d13d8)
r8: 0000000000000000  r9: 00007ffc516aaa30 r10: 00007ffc516aa988 r11: 000000000000000e
r12: 00007ffc516aaadc r13: 00007fa6dfe4f720 r14: fffff4109b7ba12a r15: 00007fa6e1448200
di: 0000000000000000  si: 0000000000000020  bp: 0000000000000000  bx: 00000bedcf1caf20
dx: 0000000000000001  ax: 0000000000000030  cx: 0000000000000001  sp: 00007ffc516aaab0
ip: 00007fa6e142c2dd efl: 0000000000010246 cgf: 002b000000000033 erf: 0000000000000005
trp: 000000000000000e msk: 0000000000000000 cr2: fffff4109b7ba15a
[end of stack trace]
Calling _exit(1). Core file will not be generated.

----------

Platform: linux (Ubuntu Linux - 18.04)
Cypress Version: 3.8.2

Directly running Xvfb and invoking cypress binary from node works well:

root@6c2f9da07ecd:/app# Xvfb :1 -screen 0 1280x800x24 &
[1] 9546
root@6c2f9da07ecd:/app# node -e "require('child_process').spawnSync('/root/.cache/Cypress/3.8.2/Cypress/Cypress', ['--no-sandbox', '--smoke-test', '--ping=89'], { env: { DISPLAY: ':1' }, stdio: 'inherit' });"
It looks like you are running the Cypress binary directly.

This is not the recommended approach, and Cypress may not work correctly.

Please install the 'cypress' NPM package and follow the instructions here:

https://on.cypress.io/installing-cypress
89

Even checked with xwd what is in the framebuffer and all fine.

So I got suspicious Xvfb is not working and added ps aux before and after smoke test is executed and turned out that Xvfb is missing -screen. Not sure if this should not be handled in @cypress/xvfb, up to maintainers.

Feel free to cancel if you already have fix elsewhere.

How has the user experience changed?

Before
Screenshot 2020-01-20 23 24 20

After
Screenshot 2020-01-20 23 24 35

PR Tasks

  • Have tests been added/updated?

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jan 20, 2020

Thanks for the contribution! Below are some guidelines Cypress uses when doing PR reviews.

  • Please write [WIP] in the title of your Pull Request if your PR is not ready for review - someone will review your PR as soon as the [WIP] is removed.
  • Please familiarize yourself with the PR Review Checklist and feel free to make updates on your PR based on these guidelines.

PR Review Checklist

If any of the following requirements can't be met, leave a comment in the review selecting 'Request changes', otherwise 'Approve'.

User Experience

  • The feature/bugfix is self-documenting from within the product.
  • The change provides the end user with a way to fix their problem (no dead ends).

Functionality

  • The code works and performs its intended function with the correct logic.
  • Performance has been factored in (for example, the code cleans up after itself to not cause memory leaks).
  • The code guards against edge cases and invalid input and has tests to cover it.

Maintainability

  • The code is readable (too many nested 'if's are a bad sign).
  • Names used for variables, methods, etc, clearly describe their function.
  • The code is easy to understood and there are relevant comments explaining.
  • New algorithms are documented in the code with link(s) to external docs (flowcharts, w3c, chrome, firefox).
  • There are comments containing link(s) to the addressed issue (in tests and code).

Quality

  • The change does not reimplement code.
  • There's not a module from the ecosystem that should be used instead.
  • There is no redundant or duplicate code.
  • There are no irrelevant comments left in the code.
  • Tests are testing the code’s intended functionality in the best way possible.

Internal

  • The original issue has been tagged with a release in ZenHub.

@claassistantio
Copy link

claassistantio commented Jan 20, 2020

CLA assistant check
All committers have signed the CLA.

@@ -9,6 +9,7 @@ const util = require('../util')

const xvfb = Promise.promisifyAll(new Xvfb({
timeout: 30000, // milliseconds
xvfb_args: ['-screen', '0', '1280x1024x24'], // need to explicitly define screen otherwise electron will crash
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took this value from freedesktop/xorg-xserver but there has to be something rotten with ubuntu's xvfb, because it's mentioned in man as well as in code that -screen is default to 1280x1024x24 🤔

Copy link
Contributor Author

@isnotgood isnotgood Jan 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually ubuntu uses this packag bionic/xvfb which contains older version with:

#define VFB_DEFAULT_WIDTH      1280
#define VFB_DEFAULT_HEIGHT     1024
#define VFB_DEFAULT_DEPTH         8

So I thought that Electron is freaking out because of the bit depth, but when I start Xvbf with 8bits electron is still fine with that even without -screen at all 🤷‍♂

Copy link
Contributor Author

@isnotgood isnotgood Jan 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So latest development indicates that it could be problem somewhere else and this is just red herring:

[2031:0121/105922.460578:FATAL:memory.cc(22)] Out of memory. size=65536
We detected that the Chromium Renderer process just crashed.

This is the equivalent to seeing the 'sad face' when Chrome dies.
(...)

Not sure if related thou, because some of our tests pass. Definitely not related, it was /dev/shm set to 16MB

cli/lib/exec/spawn.js Outdated Show resolved Hide resolved
@isnotgood isnotgood changed the title fix: cypress verify fails [WIP] fix: cypress verify fails Jan 21, 2020
@bahmutov
Copy link
Contributor

I have built cypress/base:ubuntu18-node12.14.1 in cypress-io/cypress-docker-images#211 and verified that this fix solves the problem. Also this fix still works in previous image cypress/base:13.6.0 for example.

Copy link
Contributor

@bahmutov bahmutov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good and solves the problem from my testing

@bahmutov bahmutov changed the title fix: cypress verify fails fix: set explicit screen when spawning own xvfb Jan 22, 2020
@bahmutov bahmutov merged commit ee0d6fa into cypress-io:develop Jan 22, 2020
@bahmutov
Copy link
Contributor

Added small unit test in 9ac5fe3

@isnotgood
Copy link
Contributor Author

Awesome, thank you @bahmutov 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cypress verify command failing
3 participants