Skip to content

Improve WebSocket exceptions to include informative messages - #129428

Merged
MihaZupan merged 2 commits into
mainfrom
copilot/improve-websocket-error-messages
Jun 18, 2026
Merged

MihaZupan merged 2 commits into
mainfrom
copilot/improve-websocket-error-messages

Conversation

Copilot AI commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

Closes #129192

Adds error messages for cases like receiving a text message that's not valid UTF-8, an invalid close status code / description.

The current behavior was an exception like

System.Net.WebSockets.WebSocketException (0x80004005): An exception caused the WebSocket to enter the Aborted state. Please see the InnerException, if present, for more details.

where there'd be no inner exception to inspect.

Copilot AI requested review from Copilot and removed request for Copilot June 15, 2026 15:25
@MihaZupan MihaZupan changed the title Fix WebSocketReceiveErrorMessageTests stream harness Improve WebSocket exceptions to include informative messages Jun 15, 2026
@MihaZupan MihaZupan added this to the 11.0.0 milestone Jun 15, 2026
@MihaZupan
MihaZupan marked this pull request as ready for review June 15, 2026 15:29
@MihaZupan
MihaZupan requested review from a team and Copilot June 15, 2026 15:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR improves diagnostic quality in System.Net.WebSockets by ensuring protocol/UTF-8 receive failures throw WebSocketException instances with informative, scenario-specific messages (instead of falling back to a generic “Aborted state” message with no inner exception).

Changes:

  • Updates ManagedWebSocket receive/close error paths to pass explicit resource-based error messages into CloseWithReceiveErrorAndThrowAsync.
  • Adds new SR string resources for invalid UTF-8 text payload, protocol violation, invalid close status code, and invalid close description UTF-8.
  • Adds/updates tests to validate the new exception messages for invalid UTF-8 and malformed close frames.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/libraries/System.Net.WebSockets/tests/WebSocketUtf8Tests.cs Asserts the new invalid-UTF8 payload exception message in existing UTF-8 validation tests.
src/libraries/System.Net.WebSockets/tests/WebSocketReceiveErrorMessageTests.cs New tests that synthesize invalid frames and validate WebSocketException.Message / InnerException.
src/libraries/System.Net.WebSockets/tests/System.Net.WebSockets.Tests.csproj Includes the new test file in the test project compilation list.
src/libraries/System.Net.WebSockets/src/System/Net/WebSockets/ManagedWebSocket.cs Supplies explicit error messages for invalid UTF-8 payload and malformed close payload scenarios.
src/libraries/System.Net.WebSockets/src/Resources/Strings.resx Adds new localized resource strings used by the improved exceptions.

@MihaZupan
MihaZupan enabled auto-merge (squash) June 15, 2026 15:37
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @karelz, @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

@MihaZupan

Copy link
Copy Markdown
Member

/ba-g naot timeout in helix

@MihaZupan
MihaZupan merged commit 46c393a into main Jun 18, 2026
106 of 108 checks passed
@MihaZupan
MihaZupan deleted the copilot/improve-websocket-error-messages branch June 18, 2026 13:34
@dotnet-milestone-bot dotnet-milestone-bot Bot modified the milestones: 11.0.0, 11.0-preview6 Jun 19, 2026
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Web Sockets: WebSocketError.Faulted is uninformative: Add and use ProtocolError and InvalidEncodedText

4 participants