cypress-io / cypress

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

Websocket Connection Closed: When `BrowserCriClient` destroys an extra target while that target is being initialized, the App crashes #30100

Closed cacieprins closed 1 week ago

cacieprins commented 3 weeks ago

Current behavior

If BrowserCriClient's _onTargetDestroyed event handler is triggered while the _onAttachToTarget event handler is pending the Fetch.enable CRI command, the app can crash with an uncaught exception, Error: WebSocket connection closed.

This is a separate manifestation of the WebSocket connection closed issue that was resolved in the CriClient class in v13.13.1.

Desired behavior

No response

Test code to reproduce

None currently, but should be reproducible with a unit test in packages/server/test/unit/browsers/browser-cri-client_spec.ts

Cypress Version

13.13.1

Node version

18.17.1

Operating System

OSX 14.3

Debug Logs

2024-08-23T01:22:08.390Z cypress:server:browsers:browser-cri-client Target.attachedToTarget { targetId: 'EB14338F830B61BC0944C09E4C812677', type: 'page', title: '', url: '', attached: true, canAccessOpener: false, browserContextId: 'BB40F3CCEE2CA5D8CB25D667E5AB23E2' }
2024-08-23T01:22:08.395Z cypress:server:browsers:browser-cri-client Connect as extra target (id: EB14338F830B61BC0944C09E4C812677)
WebSocket connection closed
2024-08-23T01:22:08.434Z cypress:server:browsers:browser-cri-client Target.targetDestroyed { event: { targetId: 'EB14338F830B61BC0944C09E4C812677' }, closing: false, closed: false, resettingBrowserTargets: false }
2024-08-23T01:22:08.434Z cypress:server:browsers:browser-cri-client Close extra target client (id: %s)
Error: WebSocket connection closed
    at _._handleConnectionClose (<embedded>:628:580021)
    at A.<anonymous> (<embedded>:628:578085)
    at Object.onceWrapper (node:events:629:26)
    at A.emit (node:events:514:28)
    at A.emitClose (<embedded>:628:558309)
    at Socket.H (<embedded>:628:565620)
    at Socket.emit (node:events:514:28)
    at TCP.<anonymous> (node:net:323:12)

Other

No response

allenbilar commented 1 week ago

Hello, any update on this? We're consistently experience this failure on our automated test in CI. Would like to know when the fix can be possibly released? Thanks!

image

image

jennifer-shehane commented 1 week ago

@allenbilar There's a PR open that will hopefully fix this. We won't really know until it's released and used by users to ensure this covers all of these issues. https://github.com/cypress-io/cypress/pull/30174

cypress-bot[bot] commented 1 week ago

Released in 13.14.2.

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