cypress-io / cypress

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

Close extra target cause Target.targetDestroyed, and then case failed #28916

Open 7999 opened 8 months ago

7999 commented 8 months ago

Current behavior

case failed due to:

cypress:server:cypress exiting with err Error: We detected that the Custom Chrome tab running Cypress tests closed unexpectedly

Desired behavior

No response

Test code to reproduce

it's sporadic

Cypress Version

13.6.0

Node version

18.17.1

Operating System

windows10 19045.3930

Debug Logs

2024-02-06T21:18:39.150Z cypress:server:browsers:cri-client registering CDP on event { eventName: 'Inspector.targetReloadedAfterCrash' }
2024-02-06T21:18:39.152Z cypress:server:browsers:browser-cri-client Attaching to target url about:blank
2024-02-06T21:18:39.153Z cypress:server:browsers:browser-cri-client error finding browser target, maybe retrying { delay: 100, err: Error: Could not find url target in browser about:blank. Targets were [] at <embedded>:4454:82918 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async n (<embedded>:4454:81949) at async Object.open (<embedded>:4460:51628) at async Object.open (<embedded>:4460:27335) at async v.relaunchBrowser (<embedded>:4526:36933) }
2024-02-06T21:18:39.169Z cypress:server:browsers:browser-cri-client Target.attachedToTarget { targetId: 'FA6AEABA17BE62427529A1875D42765F', type: 'page', title: '', url: '', attached: true, canAccessOpener: false, browserContextId: '8B716CFACD9C62A2976C0B7338D69EE5' }
2024-02-06T21:18:39.252Z cypress:server:browsers:browser-cri-client Connect as extra target (id: FA6AEABA17BE62427529A1875D42765F)
2024-02-06T21:18:39.258Z cypress:server:browsers:browser-cri-client Attaching to target url about:blank
2024-02-06T21:18:39.258Z cypress:server:browsers:cri-client connecting { connected: false, target: 'FA6AEABA17BE62427529A1875D42765F' }
2024-02-06T21:18:39.280Z cypress:server:browsers:cri-client connected { connected: true, target: 'FA6AEABA17BE62427529A1875D42765F' }
2024-02-06T21:18:39.345Z cypress:server:browsers:cri-client registering CDP on event { eventName: 'Runtime.bindingCalled' }
2024-02-06T21:18:39.347Z cypress:server:browsers:cri-client registering CDP on event { eventName: 'Runtime.bindingCalled' }
2024-02-06T21:18:39.347Z cypress:server:socket-base socket connected

......

2024-02-06T21:18:45.580Z cypress:server:socket-base backend:request { eventName: 'close:extra:targets', args: [] }
2024-02-06T21:18:45.581Z cypress:server:browsers getBrowserLauncher { browser: { name: 'chrome', family: 'chromium', channel: 'stable', displayName: 'Custom Chrome', versionRegex: /Google Chrome (\S+)/m, binary: [ 'google-chrome', 'chrome', 'google-chrome-stable' ], minSupportedVersion: 64, info: 'Loaded from D:chrome-win\\\\chrome.exe', custom: true, path: 'D:\\\\chrome-win\\\\chrome.exe', version: '109.0.5412.0', majorVersion: '109', isHeadless: true, isHeaded: false } }
2024-02-06T21:18:45.581Z cypress:server:socket-base backend:request { eventName: 'reset:server:state', args: [] }
2024-02-06T21:18:45.581Z cypress:server:remote-states resetting remote state
2024-02-06T21:18:45.581Z cypress:server:browsers:browser-cri-client Close extra target (id: FA6AEABA17BE62427529A1875D42765F)
2024-02-06T21:18:45.584Z cypress:server:browsers:browser-cri-client Target.targetDestroyed { event: { targetId: 'FA6AEABA17BE62427529A1875D42765F' }, closing: false, closed: false, resettingBrowserTargets: false }
2024-02-06T21:18:45.584Z cypress:server:browsers:cri-client closing cri client { closed: false, target: 'FA6AEABA17BE62427529A1875D42765F' }
2024-02-06T21:18:45.586Z cypress:server:browsers:cri-client encountered closed websocket on send { command: 'Runtime.evaluate', params: { expression: '\n' + "        if (window['cypressSocket-/__socket/default'] && window['cypressSocket-/__socket/default'].send) {\n" + `          window['cypressSocket-/__socket/default'].send('"42/__socket/default,[\\\\"c54721e9-1300-44c8-9030-9e38b5e0fad1\\\\",\\\\"833f9cce-51da-403d-9779-5d78bd3d0be8\\\\",[{}]]"')\n` + '        }\n' + '      ', contextId: 2 }, sessionId: undefined, err: Error: WebSocket is not open: readyState 2 (CLOSING) at O (<embedded>:2466:564310) at A.send (<embedded>:2466:559636) at _._enqueueCommand (<embedded>:2466:580382) at <embedded>:2466:577627 at new Promise (<anonymous>) at _.send (<embedded>:2466:577601) at Object.send (<embedded>:4454:45479) at <embedded>:4479:25889 }
2024-02-06T21:18:45.586Z cypress:server:browsers:cri-client enqueueing command {
  command: 'Runtime.evaluate',
  params: {
    expression: '\n' +
      "        if (window['cypressSocket-/__socket/default'] && window['cypressSocket-/__socket/default'].send) {\n" +
      `          window['cypressSocket-/__socket/default'].send('"42/__socket/default,[\\\\"c54721e9-1300-44c8-9030-9e38b5e0fad1\\\\",\\\\"833f9cce-51da-403d-9779-5d78bd3d0be8\\\\",[{}]]"')\n` +
      '        }\n' +
      '      ',
    contextId: 2
  }
}
2024-02-06T21:18:45.586Z cypress:server:browsers:cri-client disconnected, starting retries to reconnect... { closed: true, target: 'FA6AEABA17BE62427529A1875D42765F' }
2024-02-06T21:18:45.586Z cypress:server:browsers:cri-client disconnected, not reconnecting because client is closed { closed: true, target: 'FA6AEABA17BE62427529A1875D42765F' }
2024-02-06T21:18:45.586Z cypress:server:browsers:cri-client connection was closed was trying to reconnect
2024-02-06T21:18:45.587Z cypress:server:browsers:cri-client closed cri client { closed: true, target: 'FA6AEABA17BE62427529A1875D42765F' }
2024-02-06T21:18:45.593Z cypress:server:util:socket_allowed allowed socket closed, removing { localPort: 60998 }
2024-02-06T21:18:46.090Z cypress:server:browsers:browser-cri-client browser websocket did not close, page was closed { targetId: 'FA6AEABA17BE62427529A1875D42765F' }
2024-02-06T21:18:46.093Z cypress:server:run onError
2024-02-06T21:18:46.094Z cypress:server:cypress exiting with err Error: We detected that the Custom Chrome tab running Cypress tests closed unexpectedly.

We have failed the current spec and aborted the run.

Other

No response

jennifer-shehane commented 8 months ago

@7999 Could you provide a reproducible example?

Does this error happen on Cypress version prior to 13.6.0?

7999 commented 8 months ago

@jennifer-shehane

  1. sorry, I can't provide an example, because it only happened on our pipeline agent and very sporadic, can't reproduce on local machine. from the log, it can be found that the issue occurred on the step of beforeEach.

2 this issue only happened after we update the version to 13.6.0. BTW, we update the version from 9.3.1 to 13.6.0

jennifer-shehane commented 8 months ago

@7999 Could you try Cypress 13.5.1 to see if the issue is resolved in that version?

7999 commented 8 months ago

@jennifer-shehane fine, but it will take some time.

7999 commented 7 months ago

try version 13.5.1 and monitoring.

jennifer-shehane commented 7 months ago

@7999 Any updates?

7999 commented 7 months ago

@jennifer-shehane still monitoring with version 13.5.1, night build pipeline run succussed one week, need more data to prove

7999 commented 7 months ago

@jennifer-shehane the version 13.5.1 works well more than two weeks now

7999 commented 7 months ago

@jennifer-shehane is there any plan to fix this issue in new version?

jennifer-shehane commented 7 months ago

@7999 Is this happening in newer versions? My assumption was that this was resolved.

7999 commented 7 months ago

@jennifer-shehane the newer version you mean greater than version 13.6.0? this issue happened on version13.6.0, we try the version 13.5.1 work well

jennifer-shehane commented 7 months ago

Sorry, I got very confused in this thread. @7999 Have you tried any of our newer versions to see if this Target.targetDestroyed error disappears? We made a change in 13.6.5 that I thought might fix this error in some cases. If not, we'll leave this open.

7999 commented 7 months ago

@jennifer-shehane we found this Target.targetDestroyed issue on version 13.6.0, and you let me try the version 13.5.1, image so only i can said is that the version 13.5.1 work well now, i don't know any newer version, because we can't switch the new version in our project casually.