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
davetapley opened this issue Apr 25, 2019 · 13 comments · Fixed by #4165
Closed

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

davetapley opened this issue Apr 25, 2019 · 13 comments · Fixed by #4165
Assignees

Comments

@davetapley
Copy link

davetapley 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

@davetapley
Copy link
Author

Work around is to unset DISPLAY prior to cypress run.

Also identified on #1556 (comment)

@jennifer-shehane
Copy link
Member

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
Copy link
Contributor

bahmutov 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
Copy link
Contributor

bahmutov 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
Copy link
Contributor

bahmutov 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
Copy link
Contributor

bahmutov commented May 8, 2019

@bahmutov bahmutov closed this as completed May 8, 2019
@bahmutov bahmutov reopened this May 8, 2019
@cypress-bot cypress-bot bot added stage: work in progress stage: needs review The PR code is done & tested, needs review and removed stage: investigating Someone from Cypress is looking into this stage: work in progress stage: needs review The PR code is done & tested, needs review labels May 9, 2019
@cypress-bot
Copy link
Contributor

cypress-bot bot 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.

@cypress-bot cypress-bot bot removed the stage: needs review The PR code is done & tested, needs review label May 13, 2019
@bahmutov
Copy link
Contributor

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
Copy link
Contributor

cypress-bot bot commented May 17, 2019

Released in 3.3.0.

@brian-mann
Copy link
Member

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
Copy link
Member

The warning looks like this...

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

@jennifer-shehane
Copy link
Member

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

@joeosburn
Copy link

I'm trying to run cypress using headless Chrome. When I do it, I get an error about Xvfb missing:

~ $ cypress run --headless --browser chrome
It looks like this is your first time using Cypress: 4.5.0

  ✖  Verifying Cypress can run /app/.cache/Cypress/4.5.0/Cypress
    → Cypress Version: 4.5.0
Your system is missing the dependency: Xvfb

Install Xvfb and run Cypress again.

Read our documentation on dependencies for more information:

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

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

----------

Error: spawn Xvfb ENOENT

----------

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

Am I misunderstanding how to run cypress so that Xvfb is not required? Or is Xvfb still required even to run it with headless Chrome?

nemanjaglumac added a commit to metabase/metabase that referenced this issue Nov 6, 2020
* Upgrade Cypress to v5.5.0

* Needed to unset the `DISPLAY` ENV through `config.yml` to finally make this work! (Reference: cypress-io/cypress#4034 (comment))
nemanjaglumac added a commit to metabase/metabase that referenced this issue Nov 10, 2020
* Upgrade Cypress to v5.5.0

* Needed to unset the `DISPLAY` ENV through `config.yml` to finally make this work! (Reference: cypress-io/cypress#4034 (comment))
robdaemon pushed a commit to metabase/metabase that referenced this issue Nov 10, 2020
* Quarantine flaky tests (#13682) (#13683)

* Quarantine flaky tests (#13682)

* Add TODO note re: `describeWithToken`

Co-authored-by: Nemanja Glumac

* Add a circleci workflow that runs a set of Cypress smoketests (#12775)

* Add a circleci nightly workflow that runs a bigger set of Cypress smoketests

* Run this every hour while we're testing it, add a small fix to the admin test

* Smoketests: Skip some known failing tests

Co-authored-by: Ariya Hidayat <ariya@metabase.com>

* Narrow down the quarantine for chart_drill spec (#13682) (#13699)

* CI: Fix the cache key for uberjar for running smoketest (#13698)

Smoketest for OSS edition (for now)

* Fix `settings/settings.cy.spec.js` flakes (#13701)

- isolated flake (`it.only("should surface an error when validation for any field fails (#4506)", () => {...})`) passed 10x (https://github.com/nemanjaglumac/metabase-tests/actions/runs/348275781)
- the whole spec passed 20x (https://github.com/nemanjaglumac/metabase-tests/actions/runs/348306177)

* CI: Update uberjar oss key for smoketest (#13704)

* Fix Cypress flakes in `dashboard/dashboard.cy.spec.js` file (#13703)

* Fix flakes in `revisions screen` block

* Improve test assertions (there were some rendering problems, so I adjusted the assertions)

* Narrow down the quarantine for dash_drill spec (#13682) (#13706)

* Fix `metrics.cy.spec.js` flakes (#13709)

* Fix `metrics.cy.spec.js` flakes (#13682)

* Refactor the test using API

* Smoketest: run nightly at 1am PST (#13711)

1 am PST = 09:00 UTC

CircleCI cron is for UTC:
https://circleci.com/docs/2.0/workflows/#scheduling-a-workflow

* Upgrade Cypress to v5.5.0 (#13674)

* Upgrade Cypress to v5.5.0

* Needed to unset the `DISPLAY` ENV through `config.yml` to finally make this work! (Reference: cypress-io/cypress#4034 (comment))

* Improve `segments` tests with the use of API (#13718)

* Unquarantine `scenarios/pulse/pulse.cy.spec.js` (#13727)

* Unset `DISPLAY` ENV in smoketests CI group (#13732)

* Unquarantine ee `custom_drill_through/drill_through.cy.spec.js` [ci skip] (#13734)

* Unquarantine `question/nested.cy.spec.js` (#13733)

Co-authored-by: Ariya Hidayat <ariya@metabase.com>
Co-authored-by: Damon P. Cortesi <d.lifehacker@gmail.com>
Ladsgroup added a commit to wmde/query-builder that referenced this issue Mar 19, 2021
Currently, cypress is failing to start in jenkins (in gerrit) due to
this.

For more information see cypress-io/cypress#4034

Bug: T277060
Ladsgroup added a commit to wmde/query-builder that referenced this issue Mar 19, 2021
Currently, cypress is failing to start in jenkins (in gerrit) due to
this.

For more information see cypress-io/cypress#4034

Bug: T277060
Ladsgroup added a commit to wmde/query-builder that referenced this issue Mar 19, 2021
Currently, cypress is failing to start in jenkins (in gerrit) due to
this.

For more information see cypress-io/cypress#4034

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

Successfully merging a pull request may close this issue.

5 participants