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

Running cypress in headless mode should not use xvfb #16505

Closed
mrmeku opened this issue May 13, 2021 · 14 comments · Fixed by #16537
Closed

Running cypress in headless mode should not use xvfb #16505

mrmeku opened this issue May 13, 2021 · 14 comments · Fixed by #16537

Comments

@mrmeku
Copy link
Contributor

mrmeku commented May 13, 2021

Current behavior

Currently, when I use cypress in headless mode via cypress run, xvfb is still invoked. Consequently, sometimes this can make my cypress tests error out due to an error.

For example:
Cypress: Fatal IO error 11 (Resource temporarily unavailable) on X server :105.

Desired behavior

When running in headless mode, there is no need to spawn xvfb at all. This should only be done when using cypress run to run a browser in headed mode.

Versions

All versions of cypress up to 7.3.0

@mrmeku
Copy link
Contributor Author

mrmeku commented May 13, 2021

I believe the fix for this bug can be done within

isNeeded () {

If the isNeeded function where to accept an argument of whether or not the browser is running in headless mode then we could have it return false immediately. There might be a better place to make the fix though.

I would love to make a PR to fix this bug, but I'd like a little input from the maintainers as to the shape of the fix they are most comfortable with.

@flotwig
Copy link
Contributor

flotwig commented May 13, 2021

@mrmeku that sounds like the right path. Does Electron still require X to run though?

@mrmeku
Copy link
Contributor Author

mrmeku commented May 14, 2021

That's debatable. Chrome and chromium no longer need XVFB to run any more (see https://developers.google.com/web/updates/2017/04/headless-chrome)

Electron's docs, on the other hand, makes the opposite claim (https://www.electronjs.org/docs/tutorial/testing-on-headless-ci)

I suspect that the electron docs are merely out of date.

Electron would need to be launched using the --headless flag to avoid the need for xvfb, but I think if that requirement is met there's no reason I know of that it would need a display server at all

@mrmeku
Copy link
Contributor Author

mrmeku commented May 14, 2021

Running electron with the ELECTRON_RUN_AS_NODE environment variable might also be part of the magic here: https://www.electronjs.org/docs/api/environment-variables#electron_run_as_node

@mrmeku
Copy link
Contributor Author

mrmeku commented May 14, 2021

I did some experimenting with ELECTRON_RUN_AS_NODE and it seems like that strategy could pan out. The only other requirement is that when using ELECTRON_RUN_AS_NODE you can no longer require the electron package. So within packages/server, logic will need to be added to deal with that reality.

You could interact with electron via a helper file packages/server/electron which tries to require electron and if it fails, provides a mocked out version of the APIs the server tries to interact with.

Anyway, the change is definitely slightly more involved that I had hoped since electron itself doesn't expose the same display server less headless mode that chromium does.

mrmeku pushed a commit to mrmeku/cypress that referenced this issue May 16, 2021
This change checks if the environment variable
ELECTRON_RUN_AS_NODE is set. If set to true, the cypress
process is started as a normal Node.js process rather than an
electron process.

Consequently, the process does not require a display server to
run so starting a display server is skipped.
mrmeku pushed a commit to mrmeku/cypress that referenced this issue May 16, 2021
This change checks if the environment variable
ELECTRON_RUN_AS_NODE is set. If set to true, the cypress
process is started as a normal Node.js process rather than an
electron process.

Consequently, the process does not require a display server to
run so starting a display server is skipped.
mrmeku pushed a commit to mrmeku/cypress that referenced this issue May 16, 2021
This change checks if the environment variable
ELECTRON_RUN_AS_NODE is set. If set to true, the cypress
process is started as a normal Node.js process rather than an
electron process.

Consequently, the process does not require a display server to
run so starting a display server is skipped.
mrmeku pushed a commit to mrmeku/cypress that referenced this issue May 16, 2021
This change checks if the environment variable
ELECTRON_RUN_AS_NODE is set. If set to true, the cypress
process is started as a normal Node.js process rather than an
electron process.

Consequently, the process does not require a display server to
run so starting a display server is skipped.
mrmeku pushed a commit to mrmeku/cypress that referenced this issue May 16, 2021
This change checks if the environment variable
ELECTRON_RUN_AS_NODE is set. If set to true, the cypress
process is started as a normal Node.js process rather than an
electron process.

Consequently, the process does not require a display server to
run so starting a display server is skipped.
mrmeku pushed a commit to mrmeku/cypress that referenced this issue May 16, 2021
This change checks if the environment variable
ELECTRON_RUN_AS_NODE is set. If set to true, the cypress
process is started as a normal Node.js process rather than an
electron process.

Consequently, the process does not require a display server to
run so starting a display server is skipped.
@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review stage: waiting and removed stage: work in progress stage: needs review The PR code is done & tested, needs review labels May 17, 2021
@cypress-bot cypress-bot bot added stage: work in progress and removed stage: needs review The PR code is done & tested, needs review stage: work in progress labels May 25, 2021
@wrslatz
Copy link

wrslatz commented Jun 3, 2021

We've run into this all of a sudden over the past couple of days (combo of this, cypress-io/xvfb#98, and cypress-io/cypress-docker-images#54).

@mrmeku
Copy link
Contributor Author

mrmeku commented Jun 3, 2021

I'll keep hacking on my PR, I just got side tracked

@wrslatz
Copy link

wrslatz commented Jun 3, 2021

Happy to help test any changes if I can

@wrslatz
Copy link

wrslatz commented Jun 4, 2021

For now it seems like the xvfb-run -a workaround described in cypress-io/cypress-docker-images#54 is holding 🤞🏻 The issue is intermittent so it's hard to tell.

@sec0ndhand
Copy link

Would also love to resolve this, I haven't contributed much, but this would also help support people trying to utilise cypress on heroku ci here.

mrmeku pushed a commit to mrmeku/cypress that referenced this issue Jun 25, 2021
This change checks if the environment variable
ELECTRON_RUN_AS_NODE is set. If set to true, the cypress
process is started as a normal Node.js process rather than an
electron process.

Consequently, the process does not require a display server to
run so starting a display server is skipped.
mrmeku pushed a commit to mrmeku/cypress that referenced this issue Jun 28, 2021
This change checks if the environment variable
ELECTRON_RUN_AS_NODE is set. If set to true, the cypress
process is started as a normal Node.js process rather than an
electron process.

Consequently, the process does not require a display server to
run so starting a display server is skipped.
mrmeku pushed a commit to mrmeku/cypress that referenced this issue Jun 28, 2021
This change checks if the environment variable
ELECTRON_RUN_AS_NODE is set. If set to true, the cypress
process is started as a normal Node.js process rather than an
electron process.

Consequently, the process does not require a display server to
run so starting a display server is skipped.
mrmeku pushed a commit to mrmeku/cypress that referenced this issue Jun 28, 2021
This change checks if the environment variable
ELECTRON_RUN_AS_NODE is set. If set to true, the cypress
process is started as a normal Node.js process rather than an
electron process.

Consequently, the process does not require a display server to
run so starting a display server is skipped.
mrmeku pushed a commit to mrmeku/cypress that referenced this issue Jun 28, 2021
This change checks if the environment variable
ELECTRON_RUN_AS_NODE is set. If set to true, the cypress
process is started as a normal Node.js process rather than an
electron process.

Consequently, the process does not require a display server to
run so starting a display server is skipped.
mrmeku pushed a commit to mrmeku/cypress that referenced this issue Jun 28, 2021
This change checks if the environment variable
ELECTRON_RUN_AS_NODE is set. If set to true, the cypress
process is started as a normal Node.js process rather than an
electron process.

Consequently, the process does not require a display server to
run so starting a display server is skipped.
mrmeku pushed a commit to mrmeku/cypress that referenced this issue Jun 28, 2021
This change checks if the environment variable
ELECTRON_RUN_AS_NODE is set. If set to true, the cypress
process is started as a normal Node.js process rather than an
electron process.

Consequently, the process does not require a display server to
run so starting a display server is skipped.
mrmeku pushed a commit to mrmeku/cypress that referenced this issue Jun 28, 2021
This change checks if the environment variable
ELECTRON_RUN_AS_NODE is set. If set to true, the cypress
process is started as a normal Node.js process rather than an
electron process.

Consequently, the process does not require a display server to
run so starting a display server is skipped.
@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review and removed stage: waiting labels Jun 28, 2021
mrmeku pushed a commit to mrmeku/cypress that referenced this issue Jul 6, 2021
This change checks if the environment variable
ELECTRON_RUN_AS_NODE is set. If set to true, the cypress
process is started as a normal Node.js process rather than an
electron process.

Consequently, the process does not require a display server to
run so starting a display server is skipped.
@cypress-bot cypress-bot bot added stage: work in progress stage: needs review The PR code is done & tested, needs review and removed stage: needs review The PR code is done & tested, needs review stage: work in progress labels Jul 7, 2021
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jul 9, 2021

The code for this is done in cypress-io/cypress#16537, 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 Jul 9, 2021
@mrmeku
Copy link
Contributor Author

mrmeku commented Jul 9, 2021

@jennifer-shehane @flotwig Would it be possible for someone to build a cypress binary for linux now that this change has been merged so I can test out the changes in my own projects to better exercise edge cases?

@bahmutov
Copy link
Contributor

bahmutov commented Jul 9, 2021

@mrmeku see cf689dd#commitcomment-53273920

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jul 20, 2021

Released in 8.0.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v8.0.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Jul 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants