cypress-docker-images
cypress-docker-images copied to clipboard
XVFB timed out
Hey,
I am trying to setup test environment which can be run on CircleCI. Locally, everything works fine, however, when tried to tied up everything and run it on CI environment I am getting following problem:
^@^@XVFB exited with a non zero exit code.
There was a problem spawning Xvfb.
This is likely a problem with your system, permissions, or installation of Xvfb.
----------
Error: _XSERVTransSocketUNIXCreateListener: ...SocketCreateListener() failed
_XSERVTransMakeAllCOTSServerListeners: server already running
(EE)
Fatal server error:
(EE) Cannot establish any listening sockets - Make sure an X server isn't already running(EE)
----------
Platform: linux (Debian - 8.10)
Cypress Version: 3.1.0
Exited with code 1
Any idea how to solve this? Docker setup is quite straightforward, I've got three nodes apps running in parallel + mongodb + cypress in image:
Cypress Dockerfile:
FROM cypress/base:10
RUN mkdir /usr/src/app
WORKDIR /usr/src/app
RUN yarn add [email protected]
COPY cypress.json /usr/src/app/cypress.json
RUN ./node_modules/.bin/cypress verify
Cypress part in docker-compose:
cypress:
user: root
volumes:
- ./e2e:/usr/src/app/e2e
build:
context: .
dockerfile: compose/cypress/Dockerfile
network_mode: 'host'
depends_on:
- api
And I am firing tests by running docker-compose -f docker-compose.e2e.yml run cypress ./node_modules/.bin/cypress run. As I said, locally it's fine, but CI environment fails with error shared above.
I've also tried another solution - I wanted to use cypress node 10 image as base image for CircleCI and then run tests without docker, however, I need to run my apps from docker-compose and cypress image does not provide sudo and docker-compose as well.
Having the same issue when I run my docker-compose setup.
version: '3.3'
services:
angular-app:
build:
context: .
dockerfile: Dockerfile
ports:
- '80:80'
cypress-e2e:
build:
context: ./e2e
dockerfile: Dockerfile.cypress
depends_on:
- angular-app
network_mode: host
my Cypress docker file:
FROM cypress/browsers:chrome69
# set working directory
WORKDIR /usr/app-e2e
ENV PATH /usr/app-e2e/node_modules/.bin:$PATH
# install and cache app dependencies
COPY . /usr/app-e2e
RUN npm install
Also tried cypress/base as base image, but didn't change anything
@juristr
let's debug this problem
- do you have complete minimal repo I could clone and run?
- our xvfb logic is https://github.com/cypress-io/xvfb and you can see debug messages from this module by running like this https://github.com/cypress-io/xvfb#debugging
- you can also turn on debug messages from Cypress NPM package that calls XVFB with
DEBUG=cypress:cliso that should show something
We have this problem occasionally on Travis CI but not on Circle for example, so we strongly think this is due to some bugs in containers not with the logic or time outs
@bahmutov Thanks for your hints. Gonna check some of them out. I'm using a setup similar to here as I need to run a docker-compose setup on CircleCI.
Basically I'm having an Angular app that's being booted and the Cypress container then runs the tests against that. Gonna check some of your debugging tips. locally on my machine it works. On CircleCI however I get the error 🤔
Creating network "project_default" with the default driver
Creating project_angular-app_1 ...
Creating project_angular-app_1
⠙ Verifying Cypress can run /root/.cache/Cypress/3.1.0/Cypress
✖ Verifying Cypress can run /root/.cache/Cypress/3.1.0/Cypress
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.
----------
Caught error trying to run XVFB: "XVFB exited with a non zero exit code.
There was a problem spawning Xvfb.
This is likely a problem with your system, permissions, or installation of Xvfb.
----------
Error: _XSERVTransSocketUNIXCreateListener: ...SocketCreateListener() failed
_XSERVTransMakeAllCOTSServerListeners: server already running
(EE)
Fatal server error:
(EE) Cannot establish any listening sockets - Make sure an X server isn't already running(EE)
----------
Platform: linux (Debian - 8.11)
Cypress Version: 3.1.0"
----------
Platform: linux (Debian - 8.11)
Cypress Version: 3.1.0
Exited with code 1
hmm, weird, but hard for me to recreate, a complete repro would be ideal. Does this happen every time?
yes. I'll try to create a small sample repo and share it on GitHub
@bahmutov I have a repro repository here: https://github.com/juristr/nx-cypress-ci-setup
I can also add you (or anyone else) as a collaborator if that makes it easier to debug the issue. Locally it works just fine, when executed on CircleCI I get the error as seen here: https://circleci.com/gh/juristr/nx-cypress-ci-setup/3
Let me know if I can help
@juristr I did not have time to debug the issue, but take a look at https://github.com/cypress-io/xvfb - this is the XVFB module we use to try to start the server (see https://github.com/cypress-io/cypress-docker-images/issues/54#issuecomment-425439648)
Could you debug this problem in Circle by rerunning the job with SSH and maybe even editing the code in node_modules/@cypress/xvfb directly?
Could you debug this problem in Circle by rerunning the job with SSH
Oh alright, didn't know I can debug CircleCI via SSH. thx, will let you know 👍
I spent some time removing as many variables as I could to fix this problem, and it appears that running selenium alongside your other docker instances can cause this issue to appear.
I ran into the same problem. After removing network_mode: 'host' it works. Is there a fix for this?
The problem is that when running in host mode, the X server port can be shared across cypress instances, the host machine itself, or something else (selenium). To fix we should use a nonstandard port for the xvfb instance within the container. You can also find the original X server and kill it first (in my case, Circle CI machine executor image has one.)
These issues are connected https://github.com/cypress-io/cypress-docker-images/issues/39 https://github.com/cypress-io/cypress/issues/1426 https://github.com/cypress-io/cypress/issues/673 https://github.com/cypress-io/cypress/issues/457
@bahmutov Any updates here?
@tylergets would you like to implement a detection for XVFB running already (probably in https://github.com/cypress-io/xvfb) and maybe a fix?
Hi all. I've raised PR https://github.com/cypress-io/cypress/pull/5035 containing the workaround we've used in my team for this issue. We've exposed an environment variable hook to allow us to control the XVFB port used, thereby allowing us to ensure that each of the containers participating in our parallel Cypress run does so using a different port number.
While this doesn't address the underlying issue in the way that @bahmutov's suggestion would, it may at least help others work around this problem by giving them control of the XVFB port used until such time as that fix can be implemented.
we have released Cypress v3.5.0 with a timeout of 30 seconds, I hope it helps.
I was having the same issue, and what fixed it was adding:
environment:
- DISPLAY
to the cypress service in docker-compose.
Hi all. I've raised PR #54 containing the workaround we've used in my team for this issue.
@davidedwards88 The PR link just leads back to this page. Was it merged, or do you have a copy somewhere?
@thomasactia Apologies, I hadn't realised I'd included an incorrect link in my comment. I've been able to find the PR I should have referenced, which can be found at https://github.com/cypress-io/cypress/pull/5035 (I've now updated my original comment also).
As per the comments in that PR, unfortunately it went un-merged as I did not have time to address the feedback given.
I'm running into this on the newest Cypress version (6.5.0). Any chance there's an update on a fix/workaround for this issue? Happy to provide more details as needed.
I'm seeing this with Cypress version 6.6.0 and 6.4.0, using cypress/included:6.6.0 in CircleCI. Also happy to provide more details!
@dalgarno's solution worked for me, ie:
environment: - DISPLAY
So full config for docker-compose for cypress is something like:
version: "3"
services:
cypress:
build:
context: path/for/context
dockerfile: path/to/Dockerfile
# So cypress can reach localhost
network_mode: host
environment:
# Required to prevent an issue with cypress complaining about xvfb
# See https://github.com/cypress-io/cypress-docker-images/issues/54#issuecomment-569427367
DISPLAY:
# Needed so chromium doesn't crash
# See https://github.com/cypress-io/cypress/issues/350
ipc: host
I have a temporary solution to solve server already running caused by network_mode: host in my project.
Check xvfb port and generate cypress-xvfb lock file before running cypress
prepare_xvfb () {
# delete all cypress-xvfb lock file
[ -f /tmp/.X*-lock ] && rm -f /tmp/.X*-lock
local display_num=99
local loop=true
while [ $loop == 'true' ]
do
# xvfb port
if [ $display_num -ge 100 ]; then
local xvfb_port="6$display_num"
else
local xvfb_port="60$display_num"
fi
# generate cypress-xvfb lock file
nc -z 127.0.0.1 "$xvfb_port" || local occupied=false
if [[ "$occupied" == "false" ]]; then
local loop=false
else
echo "[ Info ] xvfb display number :${display_num} was occupied. Check next"
echo "<my project> placeholder" > "/tmp/.X${display_num}-lock"
let display_num++
fi
done
echo "[ Info ] xvfb will use display :${display_num}."
}
Cypress version in my project is 3.8.0 and @cypress/xvfb version is 1.2.4. Cypress-xvfb lock file used in https://github.com/cypress-io/xvfb/blob/0051191e4953a2a922086dcdc5c4aae3aecfe5b1/index.js#L128
I hit this as well, because we were running Selenium tests on the the Circle CI server as well as Cypress tests, and by the time we ran the Cypress tests we had already started Xvfb.
Simply killing Xvfb before running cypress fixed the problem: sudo pkill Xvfb.
We are seening it recently in CI with GHA large runners.. :confused: