Skip to content

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

Open
DeagleGross wants to merge 1 commit intodotnet:mainfrom
DeagleGross:dmkorolev/signalr-websocketswork-flak
Open

fix flaky Microsoft.AspNetCore.SignalR.Client.Tests.TestServerTests.WebSocketsWorks#65928
DeagleGross wants to merge 1 commit intodotnet:mainfrom
DeagleGross:dmkorolev/signalr-websocketswork-flak

Conversation

@DeagleGross
Copy link
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
Copy link
Contributor

Copilot AI left a comment

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();
Copy link

Copilot AI Mar 23, 2026

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();
Copy link

Copilot AI Mar 23, 2026

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
Copy link
Member

@BrennanConroy BrennanConroy left a comment

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.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants