Skip to content

fix(browsercontext): set closedStatus to closed after close#41806

Open
SebTardif wants to merge 2 commits into
microsoft:mainfrom
SebTardif:fix/context-closed-status
Open

fix(browsercontext): set closedStatus to closed after close#41806
SebTardif wants to merge 2 commits into
microsoft:mainfrom
SebTardif:fix/context-closed-status

Conversation

@SebTardif

Copy link
Copy Markdown
Contributor

Summary

BrowserContext._didCloseInternal guards on _closedStatus === 'closed', but that status was never set. Concurrent browserClosed() and close() (documented in the comment) both ran cleanup and emitted Close twice (tracing.abort() twice, double fulfill of the close promise).

Fix

Set _closedStatus = 'closed' at the start of _didCloseInternal after the early return, so a second entry is a no-op.

Evidence (red / green)

# Red (before fix)
Expected: 1  Received: 2  // Close events on double browserClosed()

# Green (after fix)
1 passed — second browserClosed is a no-op; isClosingOrClosed() is true

Test plan

  • New test: double browserClosed emits server close once
  • browsercontext-basic smoke still passes

_didCloseInternal guarded on status === 'closed' but never set that
value, so concurrent browserClosed and close both re-ran cleanup and
emitted Close twice.

Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>

@dgozman dgozman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this test brings any value, but the fix itself is nice. Could you please remove the test?

dgozman: the fix is fine; the test does not add value.
@SebTardif

Copy link
Copy Markdown
Contributor Author

@dgozman

I don't think this test brings any value, but the fix itself is nice. Could you please remove the test?

Removed the test in 8842642. The one-line _closedStatus = 'closed' fix is unchanged.

@github-actions

Copy link
Copy Markdown
Contributor

Test results for "MCP"

3 failed
❌ [chrome] › mcp/cli-killall.spec.ts:42 › kill-all kills filtered dashboard pid @mcp-macos-latest-chrome
❌ [chromium] › mcp/annotate.spec.ts:350 › should annotate when context has no fixed viewport @mcp-windows-latest-chromium
❌ [firefox] › mcp/annotate.spec.ts:230 › should capture annotations via show --annotate @mcp-macos-latest-firefox

7757 passed, 1249 skipped


Merge workflow run.

@github-actions

Copy link
Copy Markdown
Contributor

Test results for "tests 1"

1 flaky ⚠️ [chromium-library] › library/chromium/chromium.spec.ts:177 › serviceWorker(), and fromServiceWorker() work `@frozen-time-library-chromium-linux`

49910 passed, 1158 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