cypress: Cypress could not connect to Firefox. `Error: cannot open socket` displayed at beginning of running spec

When running cypress with options ‘–headless --browser firefox’, cypress halts at the start of the second spec with message:

Cypress could not connect to Firefox.

An unexpected error was received from Marionette connection:

Error: cannot open socket

To avoid this error, ensure sure that there are no other instances of Firefox launched by Cypress running.

This blocks running all specs in ‘run’ mode Windows 10, Firefox version 72 (64 bit)

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 39 (7 by maintainers)

Most upvoted comments

I have the same issue with cypress 4.5.0 running on Linux on a Microsoft hosted agent in Azure Devops.

Edit: I have this when trying to two runs in the same job, so first for chrome then for Firefox. If I run only for firefox it works, so it seems there is something not closed properly from the first run.

Just in case if it helps in debugging, here’s the screenshot of the error I received. image

In my case, I had selected Firefox from the dropdown in the Test Runner. And after re-trying it a couple of time, it worked fine.

Apart from this: fantastic that you are working on the Firefox option!

Maybe it will help someone.

  • (plugin config step) during test I generate special flag - instanceId (cypress.CYPRESS_GROUP.TIMESTAMP)
  • (plugin before:browser:launch) before start of firefox I append this flag to command that starts browser as --instanceId=INSTANCE_ID
  • (support after) after suite is done (one spec file) I store that instanceId to cypress/tmp/firefox/CYPRESS_GROUP.instanceId
  • then npm run killFirefoxWin (nodejs custom script based on ps-node) got to be executed. It looks for CYPRESS_GROUP in environment (or group field in cypress.env.json), if not found - “general” string will be used instead. It tries to find .instanceId file and based on instanceId from it - find main firefox process, kill it and check if any other child processes (children are linked to parent process by --channel parameter) exist - will kill them if yes.
  • in case file with instanceId is not found - fallback to kill all processes with name firefox.exe

I know that it is ugly, but I had to make it work.

I checked beforehand with the Taskmanager that no firefox processes were running. I noticed that after a run with firefox (with only one spec), a number of firefox processes stay present in the Taskmanager. When I run the same spec again with Firefox, without killing these remaining processes, cypress responds with this remark:

Warning: We failed to remove old browser profiles from previous runs.

This error will not alter the exit code.

Error: EBUSY: resource busy or locked, unlink '<path>\AppData\Roaming\Cypress\cy\production\browsers\firefox\run-9852\cert9.db'

The number of remaining Firefox processes have doubled.

Running a spec with headless chrome I see all chrome processes are neatly cleared after the run.

Same here. Running specs in Firefox from ci resulted in the same errors as described in this issue, as well as (in the timespan of a week) more than 80 running Firefox processes in the task manager eating up memory.

Option -no-remote has no effect in a Windows 10 environment. Issue remains. Tested with cypress 4.0.2

still having the issue, even after #6400

This should be fixed in #6400. In the meantime, you can pass -no-remote via the Browser Launch API while launching Firefox, which should help: https://docs.cypress.io/api/plugins/browser-launch-api.html#Modify-browser-launch-arguments-preferences-and-extensions

Do you have Firefox Developer or Nightly version installed on your system as well? Are you also running Firefox outside of Cypress when you run your tests and see this error?

The answer to both questions is ‘no’. I checked beforehand with the Taskmanager that no firefox processes were running. I noticed that after a run with firefox (with only one spec), a number of firefox processes stay present in the Taskmanager. When I run the same spec again with Firefox, without killing these remaining processes, cypress responds with this remark:

Warning: We failed to remove old browser profiles from previous runs.

This error will not alter the exit code.

Error: EBUSY: resource busy or locked, unlink '<path>\AppData\Roaming\Cypress\cy\production\browsers\firefox\run-9852\cert9.db'

The number of remaining Firefox processes have doubled.

Running a spec with headless chrome I see all chrome processes are neatly cleared after the run.

Did not have the opportunity yet to try fix #6400