Skip to content

fix(webSocketRoute): handle close events without code/reason - #3345

Merged
Dmitry Gozman (dgozman) merged 1 commit into
microsoft:mainfrom
dgozman:fix-3333
Aug 12, 2026
Merged

fix(webSocketRoute): handle close events without code/reason#3345
Dmitry Gozman (dgozman) merged 1 commit into
microsoft:mainfrom
dgozman:fix-3333

Conversation

@dgozman

Copy link
Copy Markdown
Collaborator

Summary

  • closePage / closeServer events carry optional code/reason in the protocol, but were read with throwing accessors — a routed WebSocket closed by navigation or page closure threw KeyNotFoundException inside Connection.Dispatch and killed the whole connection.
  • Read them with TryGetProperty and pass null through, matching the TypeScript client.
  • Port should emit close upon frame navigation and should not throw after page closure tests from upstream; both reproduced the crash before the fix.

Fixes #3333

The closePage/closeServer events carry optional code and reason, but
they were read with throwing accessors. When a page with a live routed
WebSocket navigated or closed, the missing properties threw
KeyNotFoundException inside Connection.Dispatch, closing the entire
connection.

Fixes: microsoft#3333
@dgozman
Dmitry Gozman (dgozman) merged commit 2eaee29 into microsoft:main Aug 12, 2026
16 checks passed
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.

[Bug]: WebSocketRoute crashes with KeyNotFoundException when a close event omits code/reason during Browser.CloseAsync with a connected mock route

2 participants