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

Presence of DISPLAY env var causes "Cypress failed to start" #4034

Closed
dukedave opened this issue Apr 25, 2019 · 12 comments

Comments

4 participants
@dukedave
Copy link

commented Apr 25, 2019

Current behavior:

  1. Have DISPLAY env var set
  2. cypress run:
Verifying Cypress can run /root/.cache/Cypress/3.2.0/Cypress [failed]
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.
----------

Command failed: /root/.cache/Cypress/3.2.0/Cypress/Cypress --smoke-test --ping=177
----------

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

Desired behavior:

cypress run runs regardless of presence of DISPLAY variable.

Steps to reproduce: (app code and test code)

This was working until a few days ago when we started observing Cypress failed to start.
Inspecting logs we noticed that Semaphore had began injecting a DISPLAY env var. We reached out to Semaphore and they confirmed:

Thanks for reporting this.

The $DISPLAY=:99 change was introduced two days ago as a part of improvements and fixes activities. This change helps with some workflows that are using Selenium/Chrome combination. Since this positively affected a given group of our users, we introduced this change.

I shared this message with the platform team and we will let you know as soon as we have any new information. Until then, please use the workaround you described.

Thanks for your patience.

Versions

@dukedave

This comment has been minimized.

Copy link
Author

commented Apr 25, 2019

Work around is to unset DISPLAY prior to cypress run.

Also identified on #1556 (comment)

@jennifer-shehane

This comment has been minimized.

Copy link
Member

commented Apr 26, 2019

Yeah, we have definitely seen this reported, but I don't recall anyone tracking down why this is occurring.

Cypress has this code that checks if the OS is linux and if there is NOT a process.env.DISPLAY set, if so - then during cypress run, it evaluates as needing XVFB and also should print needs XVFB? true in the console DEBUG output. How to see your own DEBUG logs

Looks like this is false:

cypress:cli needs XVFB? false +0ms

https://github.com/cypress-io/cypress/blob/develop/cli/lib/exec/xvfb.js#L44

So, assuming you were running on linux and had a DISPLAY env var set, this would evaluate as needs XVFB? false, so then as part of the options, stdio would evaluate to 'inherit' instead of ['inherit', 'inherit', 'pipe']

https://github.com/cypress-io/cypress/blob/devlop/cli/lib/exec/spawn.js#L33

I'm not sure this is relevant.

ALSO, if needsXVFB is false, if will not call into the xvfb.start and instead call into spawn

https://github.com/cypress-io/cypress/blob/develop/cli/lib/exec/spawn.js#L141

https://github.com/cypress-io/cypress/blob/develop/cli/lib/exec/spawn.js#L66

Then I'm a bit lost as to why or where this dependencies error is thrown...which is being caught here:

https://github.com/cypress-io/cypress/blob/issue-1369-configFile-arg/cli/lib/tasks/verify.js#L69

@brian-mann thoughts?

@bahmutov

This comment has been minimized.

Copy link
Collaborator

commented May 7, 2019

Cypress spins its own XVFB server if there is no DISPLAY variable, to see this in action

  • start Docker locally
  • from any folder execute the command
docker run -it -v $PWD:/e2e -w /e2e -e DEBUG=cypress:cli,xvfb -e DISPLAY= --entrypoint cypress cypress/included:3.2.0 verify

You should see Cypress messages

cypress:cli using Cypress executable /root/.cache/Cypress/3.2.0/Cypress/Cypress +0ms
  cypress:cli needs XVFB? true +0ms
  cypress:cli Starting XVFB +0ms
  xvfb lock filename /tmp/.X99-lock +0ms
  xvfb lock filename /tmp/.X99-lock +1ms
  xvfb setting DISPLAY :99 +0ms
  xvfb all Xvfb arguments [ ':99' ] +2ms
  xvfb checking if started by looking for the lock file /tmp/.X99-lock +4ms
  xvfb checking if started by looking for the lock file /tmp/.X99-lock +12ms
  xvfb lock file /tmp/.X99-lock found after 10 ms +1ms
  cypress:cli smoke test command: /root/.cache/Cypress/3.2.0/Cypress/Cypress --smoke-test --ping=182 +21ms
  cypress:cli smoke test stdout "182" +795ms
  cypress:cli Stopping XVFB +817ms
  xvfb restoring process.env.DISPLAY variable +798ms
  xvfb lock filename /tmp/.X99-lock +0ms
  xvfb lock file /tmp/.X99-lock +0ms
  xvfb lock file /tmp/.X99-lock not found when stopping +67ms
  cypress:cli write verified: true +690ms
  cypress:cli could not read binary_state.json file +2s
[20:59:25]  Verifying Cypress can run /root/.cache/Cypress/3.2.0/Cypress [completed]

But if this variable is set to something else, let's say :100 then verification fails

$ docker run -it -v $PWD:/e2e -w /e2e -e DEBUG=cypress:cli,xvfb -e DISPLAY=:100 --entrypoint cypress cypress/included:3.2.0 verify
  cypress:cli cli starts with arguments ["/usr/local/bin/node","/usr/local/bin/cypress","verify"] +0ms
  cypress:cli NODE_OPTIONS is not set +0ms
  cypress:cli program parsing arguments +2ms
  cypress:cli parsed cli options {} +2ms
  cypress:cli verifying Cypress app +0ms
  cypress:cli checking environment variables +0ms
  cypress:cli checking if executable exists /root/.cache/Cypress/3.2.0/Cypress/Cypress +3ms
  cypress:cli Binary is executable? : true +2ms
  cypress:cli binaryDir is  /root/.cache/Cypress/3.2.0/Cypress +0ms
  cypress:cli Reading binary package.json from: /root/.cache/Cypress/3.2.0/Cypress/resources/app/package.json +0ms
  cypress:cli Found binary version 3.2.0 installed in: /root/.cache/Cypress/3.2.0/Cypress +3ms
  cypress:cli { verified: true } +4ms
  cypress:cli is Verified ? true +2ms
  cypress:cli force verify +0ms
  cypress:cli running binary verification check 3.2.0 +1ms
It looks like this is your first time using Cypress: 3.2.0

[21:01:49]  Verifying Cypress can run /root/.cache/Cypress/3.2.0/Cypress [started]
  cypress:cli clearing out the verified version +5ms
  cypress:cli running smoke test +2ms
  cypress:cli using Cypress executable /root/.cache/Cypress/3.2.0/Cypress/Cypress +0ms
  cypress:cli needs XVFB? false +0ms
  cypress:cli smoke test command: /root/.cache/Cypress/3.2.0/Cypress/Cypress --smoke-test --ping=237 +0ms
  cypress:cli Smoke test failed: Error: Command failed: /root/.cache/Cypress/3.2.0/Cypress/Cypress --smoke-test --ping=237


    at makeError (/usr/local/lib/node_modules/cypress/node_modules/execa/index.js:172:9)
    at /usr/local/lib/node_modules/cypress/node_modules/execa/index.js:277:16
    at processTicksAndRejections (internal/process/task_queues.js:89:5) {
  code: 1,
  stdout: '',
  stderr: '',
  failed: true,
  signal: null,
  cmd: '/root/.cache/Cypress/3.2.0/Cypress/Cypress --smoke-test --ping=237',
  timedOut: false,
  killed: false
} +52ms
[21:01:49]  Verifying Cypress can run /root/.cache/Cypress/3.2.0/Cypress [failed]
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.
----------

Command failed: /root/.cache/Cypress/3.2.0/Cypress/Cypress --smoke-test --ping=237
----------

Platform: linux (Debian - 9.8)
Cypress Version: 3.2.0

Worse, if we just run tests, then the process fails silently

$ docker run -it -v $PWD:/e2e -w /e2e -e DEBUG=cypress:cli,xvfb -e DISPLAY=:100 cypress/included:3.2.0
  cypress:cli cli starts with arguments ["/usr/local/bin/node","/usr/local/bin/cypress","run"] +0ms
  cypress:cli NODE_OPTIONS is not set +0ms
  cypress:cli program parsing arguments +2ms
  cypress:cli running Cypress +1ms
  cypress:cli parsed cli options {} +33ms
  cypress:cli verifying Cypress app +0ms
  cypress:cli checking environment variables +1ms
  cypress:cli checking if executable exists /root/.cache/Cypress/3.2.0/Cypress/Cypress +2ms
  cypress:cli Binary is executable? : true +2ms
  cypress:cli binaryDir is  /root/.cache/Cypress/3.2.0/Cypress +1ms
  cypress:cli Reading binary package.json from: /root/.cache/Cypress/3.2.0/Cypress/resources/app/package.json +0ms
  cypress:cli Found binary version 3.2.0 installed in: /root/.cache/Cypress/3.2.0/Cypress +3ms
  cypress:cli { verified: true } +4ms
  cypress:cli is Verified ? true +2ms
  cypress:cli processing run options +0ms
  cypress:cli --key is not set, looking up environment variable CYPRESS_RECORD_KEY +1ms
  cypress:cli run to spawn.start args ["--run-project","/e2e"] +0ms
  cypress:cli needs XVFB? false +0ms
  cypress:cli spawning Cypress with executable: /root/.cache/Cypress/3.2.0/Cypress/Cypress +3ms
  cypress:cli spawn forcing env overrides { FORCE_COLOR: '1', DEBUG_COLORS: '1', MOCHA_COLORS: '1', FORCE_STDIN_TTY: '1', FORCE_STDOUT_TTY: '1', FORCE_STDERR_TTY: '1' } +0ms
  cypress:cli spawn args [ '--run-project', '/e2e', '--cwd', '/e2e' ] { dev: undefined, detached: false, stdio: 'inherit' } +1ms

That's it, there is no more output.

@bahmutov

This comment has been minimized.

Copy link
Collaborator

commented May 7, 2019

Hmm, we need an actual X11 check there, not just DISPLAY is set and we are good, something like xdpyinfo

$ xdpyinfo
name of display:    10.130.4.201:0
version number:    11.0
vendor string:    The X.Org Foundation
vendor release number:    11804000
X.Org version: 1.18.4
@bahmutov

This comment has been minimized.

Copy link
Collaborator

commented May 7, 2019

Need to check current develop branch to see what it outputs right now for this error on Linux, maybe we can extend the error message with DISPLAY variable (if it is set) and document the problem at https://on.cypress.io/required-dependencies

@bahmutov

This comment has been minimized.

@cypress-bot

This comment has been minimized.

Copy link

commented May 13, 2019

The code for this is done in cypress-io/cypress#4165, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@bahmutov

This comment has been minimized.

Copy link
Collaborator

commented May 13, 2019

Once released, cypress verify will look like this

root@c132eb00fcb5:/app# export export DISPLAY=foo
root@c132eb00fcb5:/app# $(npm bin)/cypress verify
It looks like this is your first time using Cypress: 3.3.0

⚠ Warning: we have caught a display problem:

          [652:0513/212901.933675:WARNING:browser_main_loop.cc(275)] <unknown>: Could not open X display
[652:0513/212901.933884:WARNING:browser_main_loop.cc(275)] Gtk: cannot open display: foo


          We will attempt to spin our XVFB server and verify again.

 ✔  Verified Cypress! /root/.cache/Cypress/3.3.0/Cypress

and cypress run will look like this

root@c132eb00fcb5:/app# export export DISPLAY=foo
root@c132eb00fcb5:/app# $(npm bin)/cypress run
⚠ Warning: Cypress process has finished very quickly with an error,
which might be related to a potential problem with how the DISPLAY is configured.

DISPLAY was set to "foo"

We will attempt to spin our XVFB server and run Cypress again.

Xlib:  extension "RANDR" missing on display ":99".
libudev: udev_has_devtmpfs: name_to_handle_at on /dev: Operation not permitted
Could not find any tests to run.

We looked but did not find a cypress.json file in this folder: /app
@cypress-bot

This comment has been minimized.

Copy link

commented May 17, 2019

Released in 3.3.0.

@brian-mann

This comment has been minimized.

Copy link
Member

commented May 17, 2019

FWIW - cypress will correctly recover from this situation and will display a warning indicating that it had to try a workaround - but otherwise this issue is completely fixed, nothing else to do.

@brian-mann

This comment has been minimized.

Copy link
Member

commented May 17, 2019

The warning looks like this...

Screen Shot 2019-05-17 at 3 01 05 PM

@jennifer-shehane

This comment has been minimized.

Copy link
Member

commented May 20, 2019

What does 'fix the problem' mean exactly? What is Cypress doing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.