Skip to content

Fix missing disconnection notifications for invalid close frames - #161

Merged
Marfusios merged 2 commits into
masterfrom
fix/issue-160-invalid-close-notification
Sep 24, 2026
Merged

Marfusios merged 2 commits into
masterfrom
fix/issue-160-invalid-close-notification

Conversation

@Marfusios

@Marfusios Marfusios commented Sep 18, 2026 •

Copy link
Copy Markdown
Owner

When ClientWebSocket rejects a close frame such as status 1100, it can enter a closed state before ReceiveAsync throws. The socket-state guard then suppresses DisconnectionHappened, leaving applications unaware of the lost connection.

Report receive failures as a single Lost notification with the original exception. Track whether the receive loop already published a server-close notification so normal closes and CancelClosing do not emit duplicates, while preserving CancelReconnection.

Adds seven regression cases using a real ClientWebSocket and a loopback server that sends raw close frames. Before the fix, the three invalid-close cases failed; the four valid-close cases passed. The existing fake-message test now waits for the server greeting before injecting messages, removing its dependency on receive-loop scheduling.

Validation:

  • dotnet test Websocket.Client.sln --no-restore --verbosity quiet — 58 passed (52 main tests and 6 integration tests).
  • dotnet build Websocket.Client.sln --configuration Release --verbosity quiet — succeeded with zero warnings or errors, including all seven library targets.
  • GitHub Actions passed on commit 75efedb: Linux build and all 58 tests; Windows .NET Framework sample and benchmark builds.
  • Independent code review found no actionable issues.

Closes #160.

@Marfusios Marfusios self-assigned this Sep 18, 2026
@Marfusios
Marfusios merged commit 62c5852 into master Sep 24, 2026
2 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.

DisconnectionHappened is not emitted when ClientWebSocket rejects an invalid close status code

1 participant