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

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

Closed
PetMou opened this issue Feb 10, 2020 · 39 comments · Fixed by #7106
Assignees
Labels

Comments

@PetMou
Copy link

PetMou commented Feb 10, 2020

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)

@PetMou
Copy link
Author

PetMou commented Feb 10, 2020

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

@thulin82
Copy link

Yes, confirmed on 4.0.1, firefox execution halts between first and second spec.
Running with "npx cypress run --browser firefox"
Windows Server 2016 (64 bit), Firefox version 72

@jennifer-shehane
Copy link
Member

jennifer-shehane commented Feb 11, 2020

I have not been able to reproduce this exactly as described, where it throws this message in between the first and second spec. I tried with --headless flag and without. Maybe this is related to Windows? cc @flotwig

I can get this to happen for several of the reasons that were happening before for me as described in #6380, but these always fail at or before the first spec file run for me. (also, I can't get these to reproduce in #6400, so I think it's been fixed).

This may be fixed as part of this PR: #6400 There are instructions for pulling down and running the fixes from this PR here: 3007c4f#commitcomment-37216685 If you can pull that down, let us know if that fixes your issue.

Also:

  • 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?

@jennifer-shehane jennifer-shehane added browser: firefox stage: needs information Not enough info to reproduce the issue v4.0.1 🐛 Issue present since 4.0.1 OS: windows labels Feb 11, 2020
@PetMou
Copy link
Author

PetMou commented Feb 11, 2020

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

@thulin82
Copy link

A bit off-topic (but related, since I would like to try out #6400):
Isn't the dev-builds accessible by npm?

@PetMou
Copy link
Author

PetMou commented Feb 12, 2020

Unfortunately #6400 did not bring the solution :(
running headless firefox resulted in the same message.
When I execute 'run --browser firefox' (not headless) the run ends with the following statement:

Error: read ECONNRESET
    at TCP.onStreamRead (internal/stream_base_commons.js:183:27)
 {
  errno: 'ECONNRESET',
  code: 'ECONNRESET',
  syscall: 'read'
}
Error: read ECONNRESET
    at TCP.onStreamRead (internal/stream_base_commons.js:183:27)

@pipesmoke120
Copy link

This may not be linked, or may assist with investigation but I found the following behaviour when using the Test Runner with Firefox:

1 - Select to run spec file A
2 - Wait for spec to complete
3 - Without closing Firefox select to run spec file B in test runner
4 - Modal appears stating:
'Firefox is already running, but is not responding. The old Firefox process must be closed to open a new window.'

@arvinder06
Copy link

arvinder06 commented Feb 12, 2020

(Run Starting)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:    4.0.1                                                                              │
  │ Browser:    Firefox 9                                                                          │
  │ Specs:      1 found (login.spec.js)                                                            │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘


────────────────────────────────────────────────────────────────────────────────────────────────────
                                                                                                    
  Running:  login.spec.js                                                                   (1 of 1)

Your project has set the configuration option: `chromeWebSecurity: false`

This option will not have an effect in Firefox. Tests that rely on web security being disabled will not run as expected.
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.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! Exit status 1
npm ERR! 
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/jenkins/.npm/_logs/2020-02-12T11_53_58_003Z-debug.log

Above log by running in MAC with only one spec. Any solution?

@flotwig
Copy link
Contributor

flotwig commented Feb 13, 2020

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

@Pegase745
Copy link

still having the issue, even after #6400

@PetMou
Copy link
Author

PetMou commented Feb 19, 2020

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

@r4nd0mfl
Copy link

r4nd0mfl commented Feb 21, 2020

+1 - #6400 doesn't fix it as stated above. Firefox stays open at end of run and a dialog pops up stating something about needing to close the browser to continue (sorry don't have a screenshot handy). This happens locally on Windows 10 environment as well as in CI

@devang-s
Copy link

devang-s commented Feb 21, 2020

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.

@chengzh2008
Copy link

I observed the similar issue with firefox.

I have test in the gitlab, both chrome and firefox using the imge cypress/included:4.1.0. Test usually takes about 4-5 minutes to finish. However, running the test with firefox 'yarn cypress:run --headless --browser firefox' hangs at the last spec until 1 hour limit of the gitlab.

@jennifer-shehane
Copy link
Member

jennifer-shehane commented Mar 18, 2020

This PR above did fix some occurances of this issue, but likely there is something else specific to the config, environment or tests that we will need to isolate.

  • What OS are you running in?
  • Can anyone provide the simplest example of test code that you are running that we can run?
  • Any configuration around the tests also.
  • Is this happening during cypress run or cypress open?

Edit: Actually, I would really like to ensure that the -no-remote arg is being passed through in Windows also. Can you paste the following into your plugins/index.js and print what the console log is from the terminal?

module.exports = (on, config) => {
  on('before:browser:launch', (browser = {}, launchOptions) => {
    console.log('LAUNCH OPTION ARGS', launchOptions.args) // print all current args
  })
}

When I run this - it prints the below.

Screen Shot 2020-03-18 at 3 36 05 PM

@thulin82
Copy link

thulin82 commented Mar 18, 2020

For me at least this is the details I can share

  • Running on Windows 10
  • Can't share my current setup, but it's nothing fancy. In my first spec: Open up a web page, do some validation. In my second spec: Open up a different web page, do some validation. Fails between specs. (works on Chrome)
  • Vanilla setup, nothing in support/command.js or support/index.js. Nothing (except your part above) in plugins/index.js
  • Running with 'npx cypress run --browser firefox'

My output:
image

Edit:
Tested with both 4.1.0 and 4.2.0
Firefox version 72.0.1 (64 bit)

@kristoisberg
Copy link

kristoisberg commented Mar 27, 2020

I can confirm that this still happens.

Versions
Windows 10
Cypress 4.2.0 (Also occurred on 4.1.0, that's the reason I upgraded)
Firefox 74.0 (64 bit) (I also tried with developer edition earlier, but I removed it to rule that out)

Command
node_modules/.bin/cypress run --browser firefox --headless

Launch options

LAUNCH OPTION ARGS [
  '-marionette',
  '-new-instance',
  '-foreground',
  '-start-debugger-server',
  '-no-remote',
  '-headless'
]

cypress.json

{
    "video": false
}

support/index.js

const resizeObserverLoopErrRe = /^ResizeObserver loop limit exceeded/;

Cypress.on("uncaught:exception", err => {
    if (resizeObserverLoopErrRe.test(err.message)) {
        return false;
    }
});

Cypress.Screenshot.defaults({
    screenshotOnRunFailure: false
});

@AnaPena
Copy link

AnaPena commented Apr 1, 2020

Did anyone found a workaround for this issue? Happens to me as well firefox instance is not being close after first spec

@Guusy
Copy link

Guusy commented Apr 1, 2020

I have the same issue in Jenkins trying to run in parallel chrome and firefox:

Jenkinsfile:
Following the official repo

pipeline {
    agent {
        docker {
            image 'cypress/browsers:node13.6.0-chrome80-ff72' 
            args '-p 3000:3000' 
        }
    }
    stages {
        stage('Install Dependencies') { 
            steps {
                sh 'npm ci'
                sh 'npm run cy:verify'
            }
        }
        stage('parallel tests E2E') {
            parallel {
                stage('Firefox') {
                    steps {
                        sh "npm run cy:run:firefox"
                    }
                }
                stage('Chrome') {
                    steps {
                        sh "npm run cy:run:chrome"
                    }
                }
            }
        }
    }
}

package.json

"cy:verify": "cypress verify",
 "cy:run:chrome": "cypress run --spec \"**/*.feature\" --browser chrome --headless",
 "cy:run:firefox": "cypress run --spec \"**/*.feature\" --browser firefox --headless"

Firefox options

Cypress:    4.1.0                                                                              
Browser:    Firefox 72 (headless)
LAUNCH OPTION ARGS [
  '-marionette',
  '-new-instance',
  '-foreground',
  '-start-debugger-server',
  '-no-remote',
  '-headless'
]

But if I only run the Firefox browser, everything works fine :

pipeline {
    agent {
        docker {
            image 'cypress/browsers:node13.6.0-chrome80-ff72' 
            args '-p 3000:3000' 
        }
    }
    stages {
        stage('Install Dependencies') { 
            steps {
                sh 'npm ci'
                sh 'npm run cy:verify'
            }
        }
        stage('Firefox') {
            steps {
                sh "npm run cy:run:firefox"
            }
        }
    }
}

@mtayfur-pointr
Copy link

mtayfur-pointr commented Apr 7, 2020

Same issue occurs in Github Actions as well. Firefox execution hangs forever, until cancelled manually.

Firefox cypress prefs:

[
  '-marionette',
  '-new-instance',
  '-foreground',
  '-start-debugger-server',
  '-no-remote',
  '-headless'
]

Actions yml file

  firefox:
    runs-on: ubuntu-16.04
    container:
      image: cypress/browsers:node12.13.0-chrome80-ff74
      options: --user 1001

    steps:
      - uses: actions/checkout@v1

      - name: npm install
        run: |
          npm install

      - name: npm run
        run: |
          nohup npm start &>/dev/null &

      - name: cypress firefox all test
        run: |
          npm run test:firefox

@poplevente
Copy link

any update on this? we get the same issue when running cypress within the azure devops pipeline, using firefox browser

@thulin82
Copy link

Still existing in 4.4.0

@jennifer-shehane
Copy link
Member

There are no updates on this issue. An issue will be closed when it is fixed with a comment on what version it's released in. There's no need to comment asking for updates if neither of these actions is taken.

@Evertvdw
Copy link

Evertvdw commented May 6, 2020

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.

@binte
Copy link

binte commented May 7, 2020

Doing like @Evertvdw mentioned worked for me as well.

@khitrenovich
Copy link

Adding to what @Evertvdw said -

Environment: GitHub Actions, ubuntu-latest runner.
When Cypress runs Chrome and then Firefox tests in the same step, testing on FF crashes with the same error as OP posted before the first spec.

@binte
Copy link

binte commented May 7, 2020

I noticed also that, when I run the Firefox tests in its own Job, it fails with the same error. But if I do all the browser test executions in the same Job, starting with the Firefox run, it works!

Weird (and limiting) behaviour...

@mvn-srizzari
Copy link

mvn-srizzari commented May 7, 2020

Update
After consistently failing, I moved the FF job to a larger instance size and it started working. Perhaps there some timeout issue happening, as I don't believe there to be resource contention. We're using GCP and it failed on n1-standard-2, and works on n2-standard-2.
**

I believe I'm also hitting this issue. The Firefox run worked for me a few times, but now consistently fails.

Environment:
Kubernetes 1.14.10
GitLab for running Cypress
Docker Image: cypress/included:4.5.0 for Linux

args: [
     '-marionette',
     '-new-instance',
     '-foreground',
     '-start-debugger-server',
     '-no-remote',
     '-headless',
     '-profile',
     '/root/.config/Cypress/cy/production/browsers/firefox-stable/run-29'
   ]

I have two separate jobs in my pipeline, one for FF and one for Chrome. Oddly enough the FF job just hangs at the end even though it shows it failed. I can then exec into the pod and run commands. I've re-run the cypress run --browser firefox --headless command and everything executes as expected.

This happens consistently and I can pass the debug flag, so happy to provide any additional information if needed.

Excerpt of the final messages on the failed run:

cypress:server:server Got CONNECT request from firefox.settings.services.mozilla.com:443 +174ms
   cypress:https-proxy Writing browserSocket connection headers { url: 'firefox.settings.services.mozilla.com:443', headLength: 0, headers: { 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0', 'proxy-connection': 'keep-alive', connection: 'keep-alive', host: 'firefox.settings.services.mozilla.com:443' } } +580ms
   cypress:https-proxy Got first head bytes { url: 'firefox.settings.services.mozilla.com:443', head: '\u0016\u0003\u0001\u0002\u0000\u0001\u0000\u0001�\u0003\u0003\u0000�\u0019\u0016�\u0004\u0013}�����+�u_�[Ϻ��\u0014\u0019�/k�|�� ZE^t��\r�xnWK\u0002-�M�`��D' } +12ms
   cypress:network:cors Parsed URL { port: '443', tld: 'com', domain: 'mozilla' } +761ms
   cypress:server:server HTTPS request does not match URL: https://firefox.settings.services.mozilla.com:443 with props: { port: '443', tld: '<redacted>', domain: '<redacted>' } +18ms
   cypress:https-proxy Making connection to firefox.settings.services.mozilla.com:443 +10ms
   cypress:https-proxy getting proxy URL { port: 443, serverPort: 44695, sniPort: 36419, url: 'https://firefox.settings.services.mozilla.com:443' } +4ms
   cypress:server:browsers:firefox-util error in marionette { from: 'connection', err: Error: cannot open socket at Timeout.waitForSocket [as _onTimeout] (/root/.cache/Cypress/4.5.0/Cypress/resources/app/packages/server/node_modules/socket-retry-connect/index.js:37:21)     at listOnTimeout (internal/timers.js:533:17)     at processTimers (internal/timers.js:475:7) } +12s
   cypress:server:cypress exiting with err Error: Cypress could not connect to Firefox.
 An unexpected error was received from Marionette connection:
 Error: cannot open socket
 To avoid this error, ensure that there are no other instances of Firefox launched by Cypress running.
     at Object.get (/root/.cache/Cypress/4.5.0/Cypress/resources/app/packages/server/lib/errors.js:348:11)
     at /root/.cache/Cypress/4.5.0/Cypress/resources/app/packages/server/lib/browsers/firefox-util.js:262:47
  {
   isCypressErr: true,
   type: 'FIREFOX_MARIONETTE_FAILURE',
   details: undefined
 } +36s
   cypress:server:cypress calling exit 1 +2ms
 Cypress could not connect to Firefox.
 An unexpected error was received from Marionette connection:
 Error: cannot open socket
 To avoid this error, ensure that there are no other instances of Firefox launched by Cypress running.

@flotwig
Copy link
Contributor

flotwig commented May 12, 2020

I am able to reproduce the timeout connecting to the second launch of Firefox on Windows, but I only ever get the EBUSY: resource busy or locked, not the Error: cannot open socket error... using MOZ_FORCE_DISABLE_E10S=1 does not seem to help.


Let's limit discussion in this issue to the bug affecting Windows users only, where Cypress will fail to launch the second spec file because of an "Error: cannot open socket" error.

@arvinder06 @chengzh2008 @Guusy @mtayfur-pointr @khitrenovich @mvn-srizzari Discussion about intermittently encountering "Error: cannot open socket" upon launching the first spec file (which I believe all of you are experiencing) can be moved to this issue: #7159


 Browser:    Firefox 9                                                                         

Above log by running in MAC with only one spec. Any solution?

@arvinder06 Are you truly using Firefox 9? Try upgrading to the latest version, it's unlikely that a version that old will work.

@flotwig flotwig self-assigned this May 13, 2020
@cypress-bot cypress-bot bot added stage: work in progress and removed stage: needs information Not enough info to reproduce the issue labels May 13, 2020
@PetMou
Copy link
Author

PetMou commented May 25, 2020

Cypress version 4.6.0 did not solve this problem :(
After the first test, Firefox is still running, preventing the next test to start.
With every next test I get a popup from "XULRunner" : "Firefox is already active ", resulting in a whole stack of popups.
CypressFF

@cypress-bot cypress-bot bot added stage: ready for work The issue is reproducible and in scope and removed stage: work in progress labels May 27, 2020
@drumslave-git
Copy link

drumslave-git commented Jun 11, 2020

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.

@jariendupreez
Copy link

jariendupreez commented Jun 22, 2020

When I try running my test in firefox (both in test runner and command line) I get the following error Error: connect ECONNREFUSED 127.0.0.1:52415 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1128:14). I have tried upgrading my firefox version (Currently on 56.0) and updating my cypress (4.8.0). I am running my test on windows 10. I think this may be a similar issue?

image

Fixed this by upgrading firefox to 77.0.1.

@bhaskerchari
Copy link

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.

@drumslave-git ,

I liked your idea of killing the instances by writing some custom script which would atleast serve as a workaround until it is fixed by cypress team.
Can you please let me know where you are actually invoking the custom nodejs script npm run killFirefoxWin? From your comments it's not exactly clear and it would be better if you can share some code snippet on the same.

Thanks,
Bhasker

@drumslave-git
Copy link

@bhaskerchari not able to share code (company rules).
Cypress is used as a part of android apps automation, part of scenarios got to be executed in browser - done with cypress. So my tests are triggered by Java (testng), after every spec Java also invokes npm run killFirefoxWin.
If you are using JS only - you can write node js custom runner which will do same.

@bhaskerchari
Copy link

bhaskerchari commented Jun 27, 2020

@drumslave-git ,

I am more of interest in what is the event or hook that you have used when you say after every spec you are invoking "npm run killFirefoxWin"

Actually I am using JS and I have tried running the custom script in after () callback of every spec using cy.exec() but it didn't help so that's why interested in where you have invoked the custom script to kill firefox process.

@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review and removed stage: ready for work The issue is reproducible and in scope labels Jul 10, 2020
@cypress-bot cypress-bot bot added stage: pending release and removed stage: needs review The PR code is done & tested, needs review labels Jul 15, 2020
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jul 15, 2020

The code for this is done in cypress-io/cypress#7106, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jul 21, 2020

Released in 4.11.0.

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

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