Skip to content

Fix flaky RefreshChangingUserIdentifierClosesConnection test - #68096

Open
BrennanConroy wants to merge 1 commit into
mainfrom
brennanconroy-fix-flaky-refresh-test
Open

Fix flaky RefreshChangingUserIdentifierClosesConnection test#68096
BrennanConroy wants to merge 1 commit into
mainfrom
brennanconroy-fix-flaky-refresh-test

Conversation

@BrennanConroy

Copy link
Copy Markdown
Member

Summary

Fixes flakiness in the Long Polling variant of HubConnectionTests.RefreshChangingUserIdentifierClosesConnection.

Root cause

When the refresh changes the user identifier, the server aborts the connection. On dispose, the Long Polling client sends a best-effort DELETE carrying the refreshed (userB) token. That DELETE races the server's teardown:

  • If the connection hasn't been removed from the manager yet, the server's RejectIfUserChangedAsync returns 403 Forbidden (the connection is still bound to userA), and LongPollingTransport logs ErrorSendingDeleteRequest at Error level — which fails the test's VerifyNoErrorsScope.
  • Once the connection has been removed, the same DELETE gets a benign 404 and is logged at Debug.

So whether the error is logged depends purely on timing. The connection is torn down by the abort either way (the test still asserts Disconnected), so this teardown error is expected and harmless.

Only this test hits the race, because it's the only refresh test that changes the SignalR UserIdentifier while running over real Long Polling. WebSockets/SSE don't send an authenticated DELETE on dispose, and the other refresh tests keep the same user so their cleanup DELETE stays authorized.

Fix

Allow-list that one specific teardown error (LongPollingTransport / ErrorSendingDeleteRequest) via the existing expectedErrors filter on StartServer, matching the established pattern used by sibling refresh tests. The filter is deliberately narrow so genuine failures still surface.

Test-only change. Verified by running all three transports (3/3 pass) and stressing the Long Polling variant (6/6 pass).

The Long Polling variant of this test is flaky. When the refresh changes the user identifier the server aborts the connection, and on dispose the client sends a best-effort DELETE carrying the refreshed token. That DELETE races the server's teardown: if the connection hasn't been removed from the manager yet the server rejects it with 403 and LongPollingTransport logs ErrorSendingDeleteRequest, failing VerifyNoErrorsScope. Once the connection is removed the DELETE gets a benign 404, so whether the error is logged depends purely on timing.

Allow-list that specific teardown error so the timing race no longer fails the test. The connection is already closed either way, which the test still asserts.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 29, 2026 20:35
@BrennanConroy
BrennanConroy requested a review from halter73 as a code owner July 29, 2026 20:35

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 fixes flakiness in the SignalR C# client functional test HubConnectionTests.RefreshChangingUserIdentifierClosesConnection when running over Long Polling by allow-listing an expected teardown-time log event that can race with server connection cleanup.

Changes:

  • Add a logger name constant for LongPollingTransport to keep expected-error filters precise and consistent.
  • Update the refresh test to pass a narrowly-scoped expectedErrors predicate that ignores LongPollingTransport’s ErrorSendingDeleteRequest during disposal teardown.
Show a summary per file
File Description
src/SignalR/clients/csharp/Client/test/FunctionalTests/HubConnectionTests.cs Adds a constant for the Long Polling transport logger name used by test log filtering.
src/SignalR/clients/csharp/Client/test/FunctionalTests/HubConnectionTests.AuthenticationRefresh.cs Adds a narrowly-scoped expectedErrors filter to ignore a known Long Polling teardown race (ErrorSendingDeleteRequest).

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 0

@BrennanConroy
BrennanConroy requested a review from wtgodbe July 29, 2026 21:01
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.

2 participants