Skip to content

fix flaky Microsoft.AspNetCore.SignalR.Client.Tests.TestServerTests.WebSocketsWorks - #65928

Merged
DeagleGross merged 2 commits into
dotnet:mainfrom
DeagleGross:dmkorolev/signalr-websocketswork-flak
Jun 24, 2026
Merged

fix flaky Microsoft.AspNetCore.SignalR.Client.Tests.TestServerTests.WebSocketsWorks#65928
DeagleGross merged 2 commits into
dotnet:mainfrom
DeagleGross:dmkorolev/signalr-websocketswork-flak

Conversation

@DeagleGross

Copy link
Copy Markdown
Member

The WebSocketsWorks() and LongPollingWorks() tests had a race condition where implicit using/await using disposal could dispose the host's IServiceProvider while the server-side OnDisconnectedAsync was still running, causing ObjectDisposedException.

Fixes #65914

@DeagleGross DeagleGross self-assigned this Mar 23, 2026
Copilot AI review requested due to automatic review settings March 23, 2026 17:08
@DeagleGross
DeagleGross requested a review from halter73 as a code owner March 23, 2026 17:08
@DeagleGross DeagleGross added the area-signalr Includes: SignalR clients and servers label Mar 23, 2026

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

Fixes flakiness in SignalR client TestServerTests by ensuring the in-proc TestServer host isn’t disposed while server-side OnDisconnectedAsync is still running, eliminating ObjectDisposedException errors and unquarantining the affected tests.

Changes:

  • Removed quarantine annotations from WebSocketsWorks() and LongPollingWorks().
  • Added explicit connection.StopAsync() and host.StopAsync() to drive a graceful shutdown order before disposal.

Comment on lines +79 to +80
await connection.StopAsync();
await host.StopAsync();

Copilot AI Mar 23, 2026

Copy link

Choose a reason for hiding this comment

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

connection.StopAsync() / host.StopAsync() are only executed on the success path. If an earlier await/Assert throws, cleanup falls back to disposal again and can reintroduce the same race (and can also cause additional error logs during StartVerifiableLog() disposal). Consider moving the explicit stop calls into a finally so they run regardless of test failure.

Copilot uses AI. Check for mistakes.
Comment on lines +136 to +137
await connection.StopAsync();
await host.StopAsync();

Copilot AI Mar 23, 2026

Copy link

Choose a reason for hiding this comment

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

Same as above: these explicit stop calls only run on the success path. To avoid disposal-time races/log noise when the test fails early, wrap the body in a try/finally and perform connection.StopAsync() / host.StopAsync() in the finally (guarding for partially-initialized state as needed).

Copilot uses AI. Check for mistakes.
@DeagleGross
DeagleGross enabled auto-merge (squash) March 23, 2026 17:12

@BrennanConroy BrennanConroy left a comment

Copy link
Copy Markdown
Member

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 change does anything. We already have await using var connection = ...; which will close the connection before closing the host.

I'm guessing an actual server-side change is needed to improve the lifecycle handling of a closing server.

This was referenced Mar 25, 2026
This was referenced Apr 4, 2026
@BrennanConroy
BrennanConroy self-requested a review June 23, 2026 23:50
@DeagleGross
DeagleGross merged commit fbecdd7 into dotnet:main Jun 24, 2026
25 checks passed
@DeagleGross
DeagleGross deleted the dmkorolev/signalr-websocketswork-flak branch June 25, 2026 11:15
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-signalr Includes: SignalR clients and servers pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Quarantine Microsoft.AspNetCore.SignalR.Client.Tests.TestServerTests.WebSocketsWorks

4 participants