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

XVFB timed out #54

Closed
kbiedrzycki opened this issue Aug 16, 2018 · 26 comments
Closed

XVFB timed out #54

kbiedrzycki opened this issue Aug 16, 2018 · 26 comments
Labels

Comments

@kbiedrzycki
Copy link

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.

@juristr
Copy link

juristr commented Sep 28, 2018

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

@bahmutov
Copy link
Contributor

@juristr

let's debug this problem

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 bahmutov added the bug label Sep 28, 2018
@juristr
Copy link

juristr commented Sep 28, 2018

@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

@bahmutov
Copy link
Contributor

hmm, weird, but hard for me to recreate, a complete repro would be ideal. Does this happen every time?

@juristr
Copy link

juristr commented Sep 29, 2018

yes. I'll try to create a small sample repo and share it on GitHub

@juristr
Copy link

juristr commented Oct 2, 2018

@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

@bahmutov
Copy link
Contributor

bahmutov commented Oct 8, 2018

@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 #54 (comment))

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?

@juristr
Copy link

juristr commented Oct 8, 2018

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 👍

@spaceribs
Copy link

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.

@relnod
Copy link

relnod commented Mar 11, 2019

I ran into the same problem. After removing network_mode: 'host' it works. Is there a fix for this?

@tylergets
Copy link

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
cypress-io/cypress#1426
cypress-io/cypress#673
cypress-io/cypress#457

@jennifer-shehane
Copy link
Member

@bahmutov Any updates here?

@bahmutov
Copy link
Contributor

@tylergets would you like to implement a detection for XVFB running already (probably in https://github.com/cypress-io/xvfb) and maybe a fix?

@davidedwards88
Copy link

davidedwards88 commented Aug 23, 2019

Hi all. I've raised PR cypress-io/cypress#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.

@bahmutov
Copy link
Contributor

we have released Cypress v3.5.0 with a timeout of 30 seconds, I hope it helps.

@dalgarno
Copy link

I was having the same issue, and what fixed it was adding:

environment:
  - DISPLAY

to the cypress service in docker-compose.

@thomasactia
Copy link

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?

@davidedwards88
Copy link

@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 cypress-io/cypress#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.

@HartiganHM
Copy link

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.

@CelestineKao
Copy link

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!

@CelestineKao
Copy link

CelestineKao commented Mar 8, 2021

@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

@CS-Tao
Copy link

CS-Tao commented Apr 13, 2021

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

@kylebebak
Copy link

kylebebak commented May 16, 2021

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.

@Borda
Copy link

Borda commented Nov 21, 2023

We are seening it recently in CI with GHA large runners.. 😕

@MikeMcC399
Copy link
Collaborator

@Borda

We are seening it recently in CI with GHA large runners.. 😕

Do you have details about which Cypress Docker image you are using, which version of Cypress and what your host environment is?

Could you provide up-to-date logs?

@MikeMcC399
Copy link
Collaborator

Closing due to inactivity.

@MikeMcC399 MikeMcC399 closed this as not planned Won't fix, can't repro, duplicate, stale Jun 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests