problem in spawning Xvfb, server already running
Asked Answered
F

2

5

I'm trying to run 2 cypress docker container in parallel using node js spawn

docker run -v path/to/ws:/e2e -w /e2e --network host cypress/included:8.0.0 --spec 'cypress/integration/cytorus-cache/1.feature'

docker run -v path/to/ws:/e2e -w /e2e --network host cypress/included:8.0.0 --spec 'cypress/integration/cytorus-cache/2.feature'

It fails with following error;

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)

So basically, if I run 4 parallel processes, 1 of them connects to X11 server and 3 gets error.

How it can be handlled? I've already tried setting unset DISPLAY as Cypress runs in headless mode by default. But it didn't help.

Feudatory answered 20/8, 2021 at 4:22 Comment(0)
F
2

As per cypress docker documentation,

When running on Linux, Cypress needs an X11 server; otherwise it spawns its own X11 server during the test run. When running several Cypress instances in parallel, the spawning of multiple X11 servers at once can cause problems for some of them. In this case, you can separately start a single X11 server and pass the server's address to each Cypress instance using DISPLAY variable.

Since the X11 server was already running on the server, I just spawned Xvfb :99 &, then set the address export DISPLAY=:99. And passed the DISPLAY environment variable to the docker cypress container.

Feudatory answered 24/8, 2021 at 1:16 Comment(0)
A
5

I encountered the same issue when running cypress tests in parallel. The fix for me is to remove --network host from your command to avoid port conflicts. You may need to find another approach to access the services on your host.

For instance, you can use 172.17.0.1 to access the host on Docker for Linux.

Agree answered 22/8, 2021 at 1:58 Comment(3)
Thanks. Yes, --network host causing the issue. As the host machine is AWS EC2 instance, I don't know the machine address while shooting the tests. Moreover, application can be accessed with some host name like localhost.example.com due to certificates registered against *.example.comFeudatory
I have already tried -e CYPRESS_baseUrl=http://host.docker.internal:3332 & --add-host "localhost.example.com:127.0.0.1". But it didn't work. I don't want to set the base path in Cypress config. Cypress runs in headless mode so I was not expecting it to connect with X11 server. Any way to run it?Feudatory
Seems like, the problem is already described on cypress docker page. And one of solution worked. I'll verify it on jenkins and post the final solutionFeudatory
F
2

As per cypress docker documentation,

When running on Linux, Cypress needs an X11 server; otherwise it spawns its own X11 server during the test run. When running several Cypress instances in parallel, the spawning of multiple X11 servers at once can cause problems for some of them. In this case, you can separately start a single X11 server and pass the server's address to each Cypress instance using DISPLAY variable.

Since the X11 server was already running on the server, I just spawned Xvfb :99 &, then set the address export DISPLAY=:99. And passed the DISPLAY environment variable to the docker cypress container.

Feudatory answered 24/8, 2021 at 1:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.