Skip to content

fix(electron): close pages from the main process to avoid Target.closeTarget hang#41695

Open
yury-s wants to merge 1 commit into
microsoft:mainfrom
yury-s:test-electron-teardown-hang
Open

fix(electron): close pages from the main process to avoid Target.closeTarget hang#41695
yury-s wants to merge 1 commit into
microsoft:mainfrom
yury-s:test-electron-teardown-hang

Conversation

@yury-s

@yury-s yury-s commented Jul 8, 2026

Copy link
Copy Markdown
Member

Summary

  • page.close() sends CDP Target.closeTarget and resolves only on the browser-level Target.detachedFromTarget event. On Electron, when the close races a navigation that is being committed, Electron acks Target.closeTarget with success but silently drops the actual close, so the target is never destroyed and page.close() hangs forever (Electron has no unload watchdog to recover, unlike Chrome). This surfaced as flaky Electron teardown timeouts in CI (e.g. page-autowaiting-no-hang.spec.ts "assigning location to about:blank").
  • Fix in the Electron layer: a per-page custom close handler closes the page from the main process via webContents.close(), which is not subject to the CDP/navigation race. webContents.close() (without waitForBeforeUnload) closes without running beforeunload, matching page.close(runBeforeUnload: false) force-close semantics.
  • Not an Electron version regression — reproduces equally on 42.4.1 / 42.5.0 / 42.6.1.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Comment thread tests/electron/electron-app.js Outdated
@yury-s yury-s force-pushed the test-electron-teardown-hang branch from 13d604f to 7df6703 Compare July 9, 2026 22:43
@yury-s yury-s changed the title test(electron): fix teardown hang when closing windows fix(electron): close pages from the main process to avoid Target.closeTarget hang Jul 9, 2026
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@yury-s yury-s requested a review from dgozman July 10, 2026 00:59
…eTarget hang

page.close() sends CDP Target.closeTarget and waits for the browser-level
Target.detachedFromTarget event to resolve. On Electron, when the close
races a navigation that is being committed, Electron acks Target.closeTarget
with success but silently drops the actual close, so the target is never
destroyed and page.close() hangs forever (Electron has no unload watchdog to
recover, unlike Chrome).

Close the page from the main process instead via a per-page custom close
handler that calls webContents.close(). This is not subject to the CDP/
navigation race, and webContents.close() (without waitForBeforeUnload) closes
without running beforeunload, matching page.close(runBeforeUnload: false)
semantics.
@yury-s yury-s force-pushed the test-electron-teardown-hang branch from 7df6703 to f17a470 Compare July 10, 2026 01:00
@github-actions

Copy link
Copy Markdown
Contributor

Test results for "MCP"

2 failed
❌ [chromium] › mcp/annotate.spec.ts:447 › should switch screencast to -s session on show --annotate @mcp-macos-latest-chromium
❌ [webkit] › mcp/cli-killall.spec.ts:42 › kill-all kills filtered dashboard pid @mcp-ubuntu-latest-webkit

7733 passed, 1248 skipped


Merge workflow run.

@github-actions

Copy link
Copy Markdown
Contributor

Test results for "tests 1"

49516 passed, 1161 skipped


Merge workflow run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants