cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.68k stars 3.16k forks source link

Error: WebSocket connection closed (in cypress 13.13.3) #30111

Closed ricardoaranha96 closed 2 weeks ago

ricardoaranha96 commented 2 weeks ago

Current behavior

Cypress reports Error: WebSocket connection closed and stops running tests and cypress run

13.13.1 image

13.13.3 image

Desired behavior

Don't throw exceptions or give alternatives to handle this scenario.

Test code to reproduce

Not sure how to reproduce. It happens more consistently on CI and it can take many tries to trigger it.

Cypress Version

13.13.3

Node version

20.13.1

Operating System

host macOS 14.6.1 and docker Ubuntu 22.04

Debug Logs

✓ should display similar result data correctly (3343ms)

  cypress-verbose:server:browsers:cri-client:recv:[<--] received CDP message { method: 'Page.frameScheduledNavigation', params: { frameId: 'DD44667D5CA9F274E54978C1D249F3AC', delay: 0, reason: 'scriptInitiated', url: 'about:blank' } } +1ms
  cypress-verbose:server:browsers:cri-client:recv:[<--] received CDP message { method: 'Page.frameRequestedNavigation', params: { frameId: 'DD44667D5CA9F274E54978C1D249F3AC', reason: 'scriptInitiated', url: 'about:blank', disposition: 'currentTab' } } +0ms
  cypress-verbose:server:browsers:cri-client:recv:[<--] received CDP message { method: 'Page.frameStartedLoading', params: { frameId: 'DD44667D5CA9F274E54978C1D249F3AC' } } +1ms
  cypress-verbose:server:browsers:cri-client:recv:[<--] received CDP message { method: 'Page.frameClearedScheduledNavigation', params: { frameId: 'DD44667D5CA9F274E54978C1D249F3AC' } } +0ms
  cypress-verbose:server:browsers:cri-client:recv:[<--] received CDP message { id: 7, result: {}, sessionId: '508306C90AE222184974F264B5BBEF5B' } +0ms
  cypress-verbose:server:browsers:cri-client:recv:[<--] received CDP message { method: 'Target.targetInfoChanged', params: { targetInfo: { targetId: 'C90A3B83FB4C570DF1014F348C6897BD', type: 'webview', title: 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html', url: 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html', attached: true, canAccessOpener: false, browserContextId: '7EBDD017AD07F11D60BF95E88B84EC82' } } } +1ms
  cypress-verbose:server:browsers:cri-client:recv:[<--] received CDP message { method: 'Target.targetInfoChanged', params: { targetInfo: { targetId: 'C90A3B83FB4C570DF1014F348C6897BD', type: 'webview', title: 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html', url: 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html', attached: true, canAccessOpener: false, browserContextId: '7EBDD017AD07F11D60BF95E88B84EC82' } } } +0ms
  cypress-verbose:server:browsers:cri-client:recv:[<--] received CDP message { method: 'Target.detachedFromTarget', params: { sessionId: '508306C90AE222184974F264B5BBEF5B', targetId: 'C90A3B83FB4C570DF1014F348C6897BD' } } +6ms
  cypress-verbose:server:browsers:cri-client:recv:[<--] received CDP message { method: 'Target.targetInfoChanged', params: { targetInfo: { targetId: 'C90A3B83FB4C570DF1014F348C6897BD', type: 'webview', title: 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html', url: 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html', attached: false, canAccessOpener: false, browserContextId: '7EBDD017AD07F11D60BF95E88B84EC82' } } } +0ms
  cypress-verbose:server:browsers:cri-client:recv:[<--] received CDP message { method: 'Target.targetDestroyed', params: { targetId: 'C90A3B83FB4C570DF1014F348C6897BD' } } +0ms
  cypress:server:browsers:browser-cri-client Target.targetDestroyed { event: { targetId: 'C90A3B83FB4C570DF1014F348C6897BD' }, closing: false, closed: false, resettingBrowserTargets: false } +17ms
  cypress:server:browsers:browser-cri-client Close extra target client (id: +0ms)
  cypress-verbose:server:browsers:cri-client:recv:[<--] received CDP message { method: 'Target.targetInfoChanged', params: { targetInfo: { targetId: 'C90A3B83FB4C570DF1014F348C6897BD', type: 'webview', title: 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html', url: 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html', attached: false, canAccessOpener: false, browserContextId: '7EBDD017AD07F11D60BF95E88B84EC82' } } } +0ms
  cypress-verbose:server:browsers:cri-client:recv:[<--] received CDP message { method: 'Target.targetDestroyed', params: { targetId: 'C90A3B83FB4C570DF1014F348C6897BD' } } +0ms
  cypress-verbose:server:browsers:cri-client:recv:[<--] received CDP message { method: 'Page.frameDetached', params: { frameId: '90E0918E430F4518EE9DC90E27DAE7C9', reason: 'remove' } } +5ms
  cypress-verbose:server:browsers:cri-client:send:[-->] sending CDP command { id: 218, method: 'Page.getFrameTree', params: {} } +17ms
  cypress-verbose:server:browsers:cri-client:recv:[<--] received CDP message { method: 'Runtime.executionContextDestroyed', params: { executionContextId: 18, executionContextUniqueId: '2049508947913804425.2520085817014000490' } } +0ms
  cypress-verbose:server:browsers:cri-client:recv:[<--] received CDP message { method: 'Runtime.executionContextDestroyed', params: { executionContextId: 17, executionContextUniqueId: '2011511883448273242.-569925066485990170' } } +0ms
  cypress-verbose:server:browsers:cri-client:recv:[<--] received CDP message { method: 'Page.frameNavigated', params: { frame: { id: 'DD44667D5CA9F274E54978C1D249F3AC', parentId: '68D976553EEC9E35E152C05906BEB971', loaderId: 'B13919EFCB2AECA09DEAD18EA1D06852', name: "Your project: 'Test Project'", url: 'about:blank', domainAndRegistry: '', securityOrigin: '://', mimeType: 'text/html', adFrameStatus: [Object], secureContextType: 'InsecureScheme', crossOriginIsolatedContextType: 'NotIsolated', gatedAPIFeatures: [] }, type: 'Navigation' } } +0ms
  cypress-verbose:server:browsers:cri-client:recv:[<--] received CDP message { method: 'Runtime.executionContextCreated', params: { context: { id: 20, origin: 'http://www.api.local', name: '', uniqueId: '-8403886657744751283.-5309745906177611877', auxData: [Object] } } } +0ms
  cypress-verbose:server:browsers:cri-client:recv:[<--] received CDP message { method: 'Runtime.bindingCalled', params: { name: 'cypressSendToServer-/__socket/default', payload: '"42/__socket/default,[[\\"1\\",\\"2\\",\\"3\\"],\\"mocha\\",\\"f95ad1fd-42c7-4fb1-8aed-3ec592e1fc1e\\",[\\"4\\",\\"5\\"],\\"test:after:run\\",{\\"_cypressTestStatusInfo\\":\\"6\\",\\"_testConfig\\":\\"7\\",\\"id\\":\\"8\\",\\"order\\":2,\\"title\\":\\"9\\",\\"state\\":\\"10\\",\\"pending\\":false,\\"body\\":\\"11\\",\\"type\\":\\"12\\",\\"duration\\":3343,\\"wallClockStartedAt\\":\\"13\\",\\"wallClockDuration\\":3388,\\"timings\\":\\"14\\",\\"file\\":null,\\"invocationDetails\\":\\"15\\",\\"final\\":true,\\"currentRetry\\":0,\\"retries\\":0,\\"_slow\\":10000},{\\"strategy\\":\\"16\\",\\"shouldAttemptsContinue\\":false,\\"attempts\\":1,\\"outerStatus\\":\\"10\\"},{\\"testConfigList\\":\\"17\\",\\"unverifiedTestConfig\\":\\"18\\",\\"applied\\":\\"19\\"},\\"r4\\",\\"should display similar result data correctly\\",\\"passed\\",\\"() => {\\\\n        (0,_contexts_dom_interaction_context__WEBPACK_IMPORTED_MODULE_3__.thenTheTableShouldContainHeaders)(\'similar-results-table\', [\'Name\', \'Date Of Birth\', \'Gender\']);\\\\n        (0,_contexts_dom_interaction_context__WEBPACK_IMPORTED_MODULE_3__.thenTheTableShouldContainData)(\'similar-results-table\', [\\\\n            [\\\\n                `${similarResult.first_name} ${similarResult.last_name}`,\\\\n                (0,_support_date__WEBPACK_IMPORTED_MODULE_9__.dateToHumanReadable)(moment__WEBPACK_IMPORTED_MODULE_10___default()(similarResult.dob)),\\\\n                similarResult.sex,\\\\n            ],\\\\n        ]);\\\\n    }\\",\\"test\\",\\"2024-08-23T19:37:32.938Z\\",{\\"lifecycle\\":18,\\"before each\\":\\"20\\",\\"test\\":\\"21\\"},{\\"function\\":\\"22\\",\\"fileUrl\\":\\"23\\",\\"originalFile\\":\\"24\\",\\"relativeFile\\":\\"25\\",\\"absoluteFile\\":\\"26\\",\\"line\\":84,\\"column\\":5,\\"whitespace\\":\\"27\\",\\"stack\\":\\"28\\"},\\"detect-flake-and-pass-on-threshold\\",[],{},\\"complete\\",[\\"29\\",\\"30\\"],{\\"fnDuration\\":453,\\"afterFnDuration\\":0},\\"Suite.eval\\",\\"http://www.api.local/__cypress/tests?p=e2e/src/tests/orphan-result/edit.spec.ts\\",\\"webpack://manage-angular/./e2e/src/tests/orphan-result/edit.spec.ts\\",\\"e2e/src/tests/orphan-result/edit.spec.ts\\",\\"/workdir/manage-angular/e2e/src/tests/orphan-result/edit.spec.ts\\",\\"    \\",\\"Error\\\\n    at Suite.eval (http://www.api.local/__cypress/tests?p=e2e/src/tests/orphan-result/edit.spec.ts:24062:8)\\\\n    at eval (http://www.api.local/__cypress/tests?p=e2e/src/tests/orphan-result/edit.spec.ts:24038:1)\\\\n    at eval (http://www.api.local/__cypress/tests?p=e2e/src/tests/orphan-result/edit.spec.ts:24214:3)\\\\n    at eval (http://www.api.local/__cypress/tests?p=e2e/src/tests/orphan-result/edit.spec.ts:24216:12)\\\\n    at eval (<anonymous>)\\",{\\"hookId\\":\\"31\\",\\"fnDuration\\":6,\\"afterFnDuration\\":0},{\\"hookId\\":\\"32\\",\\"fnDuration\\":2866,\\"afterFnDuration\\":0},\\"h1\\",\\"h2\\"]"', executionContextId: 3 } } +0ms
  cypress-verbose:server:browsers:cri-client:recv:[<--] received CDP message { method: 'Runtime.bindingCalled', params: { name: 'cypressSendToServer-/__socket/default', payload: '"42/__socket/default,[[\\"1\\",\\"2\\",\\"3\\"],\\"mocha\\",\\"4097ee3b-cdec-41bf-b19c-31bc33083bb2\\",[\\"4\\",\\"5\\"],\\"suite end\\",{\\"id\\":\\"6\\",\\"title\\":\\"7\\",\\"root\\":true,\\"pending\\":false,\\"type\\":\\"8\\",\\"file\\":\\"9\\",\\"retries\\":-1,\\"_slow\\":10000},\\"r1\\",\\"\\",\\"suite\\",\\"e2e/src/tests/orphan-result/edit.spec.ts\\"]"', executionContextId: 3 } } +1ms
  cypress-verbose:server:browsers:cri-client:recv:[<--] received CDP message { method: 'Runtime.bindingCalled', params: { name: 'cypressSendToServer-/__socket/default', payload: '"42/__socket/default,[[\\"1\\",\\"2\\",\\"3\\"],\\"mocha\\",\\"1e9b5e51-04e8-4b82-8bae-7110abde6e9a\\",[\\"4\\",\\"5\\"],\\"end\\",{\\"end\\":\\"6\\"},\\"2024-08-23T19:37:36.329Z\\"]"', executionContextId: 3 } } +1ms

  2 passing (8s)

  cypress-verbose:server:browsers:cri-client:send:[-->] sending CDP command { id: 219, method: 'Runtime.evaluate', params: { expression: '\n' + "        if (window['cypressSocket-/__socket/default'] && window['cypressSocket-/__socket/default'].send) {\n" + `          window['cypressSocket-/__socket/default'].send('"42/__socket/default,[[\\\\"1\\\\",\\\\"2\\\\",\\\\"3\\\\"],\\\\"tests:finished\\\\",\\\\"2252692e-7654-4bc4-a26b-7979ecd5fa15\\\\",[]]"')\n` + '        }\n' + '      ', contextId: 3 } } +3ms

  (Results)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Tests:        2                                                                                │
  │ Passing:      2                                                                                │
  │ Failing:      0                                                                                │
  │ Pending:      0                                                                                │
  │ Skipped:      0                                                                                │
  │ Screenshots:  0                                                                                │
  │ Video:        false                                                                            │
  │ Duration:     7 seconds                                                                        │
  │ Spec Ran:     edit.spec.ts                                                                     │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘

  cypress-verbose:server:browsers:cri-client:recv:[<--] received CDP message { method: 'Page.frameStoppedLoading', params: { frameId: 'DD44667D5CA9F274E54978C1D249F3AC' } } +7ms
  cypress-verbose:server:browsers:cri-client:recv:[<--] received CDP message { id: 218, result: { frameTree: { frame: [Object], childFrames: [Array] } } } +0ms
  cypress-verbose:server:browsers:cri-client:recv:[<--] received CDP message { method: 'Runtime.bindingCalled', params: { name: 'cypressSendToServer-/__socket/default', payload: '"42/__socket/default,[[\\"1\\",\\"2\\",\\"3\\"],\\"2252692e-7654-4bc4-a26b-7979ecd5fa15\\",\\"3e9cd869-e675-4ef2-b07d-fcfd8c6c5a08\\",[]]"', executionContextId: 3 } } +0ms
  cypress-verbose:server:browsers:cri-client:recv:[<--] received CDP message { id: 219, result: { result: { type: 'undefined' } } } +0ms
  cypress:server:browsers:electron sendClose called, browserCriClient is set? true +10s
  cypress:server:browsers:cri-client closing +10s
  cypress:server:browsers:cri-client closing cri client { closed: false, target: '68D976553EEC9E35E152C05906BEB971' } +0ms
  cypress:server:browsers:cri-client closed cri client { closed: true, target: '68D976553EEC9E35E152C05906BEB971' } +0ms
  cypress:server:browsers:cri-client closing +0ms
  cypress:server:browsers:cri-client closing cri client { closed: false, target: 'ws://127.0.0.1:41061/devtools/browser/9fab54fa-3236-41bf-9600-a161d2c7ea32' } +0ms
  cypress:server:browsers:cri-client Encountered error on send { command: 'Runtime.runIfWaitingForDebugger', params: undefined, sessionId: 'BA09054CC5EBE8730E58D185DAEF9F11', err: Error: WebSocket connection closed at Chrome._handleConnectionClose (/root/.cache/Cypress/13.13.3/Cypress/resources/app/node_modules/chrome-remote-interface/lib/chrome.js:254:21) at WebSocket.<anonymous> (/root/.cache/Cypress/13.13.3/Cypress/resources/app/node_modules/chrome-remote-interface/lib/chrome.js:114:26)     at Object.onceWrapper (node:events:629:26)     at WebSocket.emit (node:events:514:28)     at WebSocket.emit (node:domain:489:12) at WebSocket.emitClose (/root/.cache/Cypress/13.13.3/Cypress/resources/app/node_modules/chrome-remote-interface/node_modules/ws/lib/websocket.js:246:10) at Socket.socketOnClose (/root/.cache/Cypress/13.13.3/Cypress/resources/app/node_modules/chrome-remote-interface/node_modules/ws/lib/websocket.js:1127:15)     at Socket.emit (node:events:514:28)     at Socket.emit (node:domain:489:12)     at TCP.<anonymous> (node:net:323:12)  } +1ms
  cypress:server:browsers:cri-client error classified as WEBSOCKET_NOT_OPEN_RE; enqueuing and attempting to reconnect +0ms
  cypress:server:browsers:cdp-command-queue enqueing command Runtime.runIfWaitingForDebugger +0ms
  cypress:server:browsers:cd-command-queue enqueing command Runtime.runIfWaitingForDebugger with params undefined +0ms
  cypress:server:browsers:cdp-command-queue Command enqueued; new length: 1 +0ms
  cypress:server:browsers:cd-command-queue Queue Contents: [
  cypress:server:browsers:cd-command-queue   {
  cypress:server:browsers:cd-command-queue     command: 'Runtime.runIfWaitingForDebugger',
  cypress:server:browsers:cd-command-queue     params: undefined,
  cypress:server:browsers:cd-command-queue     deferred: {
  cypress:server:browsers:cd-command-queue       resolve: [Function (anonymous)],
  cypress:server:browsers:cd-command-queue       reject: [Function (anonymous)],
  cypress:server:browsers:cd-command-queue       promise: [Promise]
  cypress:server:browsers:cd-command-queue     },
  cypress:server:browsers:cd-command-queue     sessionId: 'BA09054CC5EBE8730E58D185DAEF9F11'
  cypress:server:browsers:cd-command-queue   }
  cypress:server:browsers:cd-command-queue ] +0ms
  cypress:server:browsers:cri-client preparing to reconnect +0ms
  cypress:server:browsers:cri-client Target ws://127.0.0.1:41061/devtools/browser/9fab54fa-3236-41bf-9600-a161d2c7ea32 disconnected, not reconnecting because client is closed. +0ms
  cypress:server:browsers:cdp-command-queue clearing command queue +0ms
  cypress:server:browsers:cri-client closed cri client { closed: true, target: 'ws://127.0.0.1:41061/devtools/browser/9fab54fa-3236-41bf-9600-a161d2c7ea32' } +0ms
  cypress:server:browsers:cri-client connection was closed was trying to reconnect +0ms
  cypress:server:browsers:electron closed event fired +3ms
  cypress:server:browsers browser instance exit event received { code: undefined, signal: undefined } +3s
  cypress:server:browsers:electron clearInstanceState called with options { options: {} } +0ms
  cypress:server:browsers:electron closing remote interface client +0ms
  cypress:server:browsers:browser-cri-client browser cri client is already closed +17ms
  cypress:server:browsers:browser-cri-client error running Runtime.runIfWaitingForDebugger: Error: Runtime.runIfWaitingForDebugger will not run as browser CRI connection was reset
    at CriClient.send (/root/.cache/Cypress/13.13.3/Cypress/resources/app/packages/server/lib/browsers/cri-client.js:219:47)
    at run (/root/.cache/Cypress/13.13.3/Cypress/resources/app/packages/server/lib/browsers/browser-cri-client.js:328:17)
    at Function._onAttachToTarget (/root/.cache/Cypress/13.13.3/Cypress/resources/app/packages/server/lib/browsers/browser-cri-client.js:399:9)
    at Chrome.<anonymous> (/root/.cache/Cypress/13.13.3/Cypress/resources/app/packages/server/lib/browsers/browser-cri-client.js:272:13)
 +0ms

================================================================================

  (Run Finished)

       Spec                                              Tests  Passing  Failing  Pending  Skipped  
  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ ✔  edit.spec.ts                             00:07        2        2        -        -        - │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘
    ✔  All specs passed!                        00:07        2        2        -        -        -  

  cypress:server:browsers browsers.kill called with no active instance +46ms

Other

I opened a similar issue to report that it occurred in Cypress 13.10. A fix was released on 13.13.1, but the error is still present on both 13.13.1 and the latest version (13.13.3).

jennifer-shehane commented 2 weeks ago

I think this may be related to https://github.com/cypress-io/cypress/issues/30100 where we did find another situation where we're not cleaning up the BrowserCriClient properly and we have a repro.

ricardoaranha96 commented 2 weeks ago

Okay, I hope my debug log is useful to the investigation. When I started to gather the evidence, #30100 was not opened.

jennifer-shehane commented 2 weeks ago

I'm going to close this as a duplicate of https://github.com/cypress-io/cypress/issues/30100 If the fix for that doesn't resolve this issue however, it could technically be a separate issue.