Cypress: WebSocket is not open: readyState 3 (CLOSED) error when watching test files

Created on 13 Nov 2019  路  26Comments  路  Source: cypress-io/cypress

Current behavior:

I edited and saved a test file and got this error printed to the Command Log.

WebSocket is not open: readyState 3 (CLOSED)

The error did not disappear upon refresh / reload. I had to kill the Cypress process and restart. Was fixed after this.

Screen Shot 2019-11-12 at 12 58 59 PM

Screen Shot 2019-11-12 at 12 59 11 PM copy

Steps to reproduce: (app code and test code)

Unfortunately this did not happen again, so I don't know what may have caused this. Documenting for anyone that captures more DEBUG logs in the future.

Versions

3.6.1

chrome

Most helpful comment

I get this if I leave cypress open while I make a coffee. Have to close the browser and click "run all specs" again

a mocha ?

All 26 comments

Hi,
I have a similar behaviour I can reproduce easily.

Here is my tests organization :
image

Step 1 : run smoke.spec.js :
image
image

Step 2 : run first e2e/ test : OK
Step 3 : run smoke.spec.js again : OK

I can reproduce this issue when testing on localhost.

On a proper QA environment, the smoke.spec.js test is always faulty.

Configuration : cypress 3.6.1 / chrome 77
It works fine on electron 73.

Hope it helps !

I've seen this multiple times. It seems to happen when I leave the browser open for an extended period of time (usually overnight between working sessions). When I try to run the tests again, I get this error and need to close and re-open the browser for tests to run.

I get this if I leave cypress open while I make a coffee. Have to close the browser and click "run all specs" again

Same as above^ I get it when it's open for a period of time and then return to it and run a test

I confirmed this only seems to occur in Chrome (78 for me) and not in Electron 73.

yes, it happens to me aswell when i updated to 3.7 and happening only on chrome :(
not sure if it is because i am using automocker plugin aswell

 functionality "before each" hook for " functionality":
     Error: WebSocket is not open: readyState 3 (CLOSED)

Because this error occurred during a 'before each' hook we are skipping the remaining tests in the current suite: '.'
      at WebSocket.send (/Users//Library/Caches/Cypress/3.7.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/ws/lib/websocket.js:329:19)
      at Chrome._enqueueCommand (/Users//Library/Caches/Cypress/3.7.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/chrome-remote-interface/lib/chrome.js:281:18)
      at Chrome.send (/Users//Library/Caches/Cypress/3.7.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/chrome-remote-interface/lib/chrome.js:83:18)
      at Chrome.tryCatcher (/Users//Library/Caches/Cypress/3.7.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/util.js:16:23)
      at Chrome.ret [as send] (<anonymous>:13:39)
      at /Users//Library/Caches/Cypress/3.7.0/Cypress.app/Contents/Resources/app/packages/server/lib/browsers/cri-client.js:103:28
      at tryCatcher (/Users//Library/Caches/Cypress/3.7.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/util.js:16:23)
      at /Users//Library/Caches/Cypress/3.7.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/method.js:15:34
      at getAllCookies (/Users//Library/Caches/Cypress/3.7.0/Cypress.app/Contents/Resources/app/packages/server/lib/browsers/cdp_automation.js:63:16)
      at onRequest (/Users//Library/Caches/Cypress/3.7.0/Cypress.app/Contents/Resources/app/packages/server/lib/browsers/cdp_automation.js:94:24)
      at /Users//Library/Caches/Cypress/3.7.0/Cypress.app/Contents/Resources/app/packages/server/lib/automation/index.js:82:20
      at Object.getCookies (/Users//Library/Caches/Cypress/3.7.0/Cypress.app/Contents/Resources/app/packages/server/lib/automation/cookies.js:63:16)
      at /Users//Library/Caches/Cypress/3.7.0/Cypress.app/Contents/Resources/app/packages/server/lib/automation/index.js:94:30
      at tryCatcher (/Users//Library/Caches/Cypress/3.7.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/util.js:16:23)
      at Function.Promise.attempt.Promise.try (/Users//Library/Caches/Cypress/3.7.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/method.js:39:29)
      at normalize (/Users//Library/Caches/Cypress/3.7.0/Cypress.app/Contents/Resources/app/packages/server/lib/automation/index.js:89:30)
      at /Users//Library/Caches/Cypress/3.7.0/Cypress.app/Contents/Resources/app/packages/server/lib/automation/index.js:139:20
      at tryCatcher (/Users//Library/Caches/Cypress/3.7.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/util.js:16:23)
      at Promise._settlePromiseFromHandler (/Users//Library/Caches/Cypress/3.7.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/promise.js:547:31)
      at Promise._settlePromise (/Users//Library/Caches/Cypress/3.7.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/promise.js:604:18)
      at Promise._settlePromiseCtx (/Users//Library/Caches/Cypress/3.7.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/promise.js:641:10)
      at _drainQueueStep (/Users//Library/Caches/Cypress/3.7.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/async.js:97:12)
      at _drainQueue (/Users//Library/Caches/Cypress/3.7.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/async.js:86:9)
      at Async._drainQueues (/Users//Library/Caches/Cypress/3.7.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/async.js:102:5)
      at Immediate.Async.drainQueues [as _onImmediate] (/Users//Library/Caches/Cypress/3.7.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/async.js:15:14)
      at processImmediate (internal/timers.js:443:21)

I get this if I leave cypress open while I make a coffee. Have to close the browser and click "run all specs" again

a mocha ?

i am facing this with 3.8.0 too when i run 50 test cases it weirdly starts happening after 10-15 test case runs

i am facing this with 3.8.0 too when i run 50 test cases it weirdly starts happening after 10-15 test case runs

It's my problem too.

Here is the example i created to recreate this. Run it from CLI

npx cypress run --browser chrome

https://github.com/ayandebbarman/CypressWebSocket

This one is also preventing from using CLI.. I am surprised that more people are not facing this yet

I have seen the same issue. Chrome 79, Cypress 3.8.0. Did not see this on 3.4.1.

By the way, I am using Cypress with a proxy. Could this be related to that combo?

By the way, I am using Cypress with a proxy. Could this be related to that combo?

No don't think I created a simple example to reproduce with simple cy visit test cases and can reproduce it. Cypress changed lot of things including the way they cypress controls browser from 3.5.0 and its still getting stabilized so the issues have started coming since that version.. Below is the simple example to reproduce the issue

https://github.com/ayandebbarman/CypressWebSocket

just checked. Issue still occurring for 3.8.1

Same here. Any progress on that?

I also get this issue when leaving the browser for a short time.

Apparently this is related to version of Chrome. I get this problem almost every time when trying to start a spec file on Cypress 3.8.3 with Chrome 79.0.3945.130. When I instead use the built in Electron browser (78) it works fine.

Updated to Chrome 80.0.3987.87, still the same issue.
On Windows 10, using chrome 64-bit by the way.

Also experiencing this. Getting it after a few minutes of working (TDD style)

This is caused by the Chrome DevTools Protocol connection unexpectedly disconnecting. Then, when we go to send a new command after some inactivity, the socket throws an error because it's closed.

We discussed reconnecting to CDP automatically; however, this could result in non-deterministic behavior (one example: how do you generically handle commands that have been sent but not responded to if CDP disconnected?). Instead, Cypress should:

  1. send a simple CDP message at an interval to keep the socket connection open, and
  2. if the CDP connection disconnects, immediately propagate the error, instead of waiting for the next command to run

Here is the example i created to recreate this. Run it from CLI

npx cypress run --browser chrome

ayandebbarman/CypressWebSocket

This one is also preventing from using CLI.. I am surprised that more people are not facing this yet

@ayandebbarman This example repo passes for me in Windows & Linux with Chrome 80 and Cypress 4.0.2. Are you still experiencing this issue on 4.0.2?

Here is the example i created to recreate this. Run it from CLI
npx cypress run --browser chrome
ayandebbarman/CypressWebSocket
This one is also preventing from using CLI.. I am surprised that more people are not facing this yet

@ayandebbarman This example repo passes for me in Windows & Linux with Chrome 80 and Cypress 4.0.2. Are you still experiencing this issue on 4.0.2?

Haven't upgraded to 4.0.2 yet .. will give it a try

Steps to reproduce

So this happens definitely after I have put my Mac to sleep.

  • Have Cypress open using cypress open in my project.
  • Put Mac to sleep
  • Wake Mac and rerun tests

Screen Shot 2020-02-24 at 3 29 08 PM

There may be some other situations this happens, particularly since I've seen Windows users mention this, but for some reason the connection is being disconnected. Anyways, it's good news that we have a way to reproduce because now we can verify a fix!

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

Released in 4.1.0.

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

Was this page helpful?
0 / 5 - 0 ratings