Fix SignalR TS client access token retry when HttpClient throws on 401#67851
Open
Arul1998 wants to merge 1 commit into
Open
Fix SignalR TS client access token retry when HttpClient throws on 401#67851Arul1998 wants to merge 1 commit into
Arul1998 wants to merge 1 commit into
Conversation
The HttpClient implementations throw an HttpError for non-2xx responses, so the 401 handling in AccessTokenHttpClient never executed for SSE keep-alive pings and LongPolling requests. Catch a thrown 401, renew the access token via the factory, and retry the request once, matching the existing non-throwing retry behavior. Fixes dotnet#56494
Author
|
@dotnet-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix SignalR TypeScript client access token retry when the HttpClient throws on 401
Description
In the browser/TypeScript SignalR client,
AccessTokenHttpClient.sendcontains retry logic that is meant to renew the access token via the access token factory and resend the request when a 401 Unauthorized is received. However, theHttpClientimplementations (e.g.FetchHttpClient) throw anHttpErrorfor non-2xx responses, so theresponse.statusCode === 401check after theawaitis never reached — the thrown error propagates instead and the token is never renewed.This notably affects:
What changed
AccessTokenHttpClient.sendnow catches a thrownHttpErrorwith status code 401 (subject to the sameallowRetryconditions as the existing logic), renews the access token via the factory, sets the newAuthorizationheader, and resends the request once. The retried request is intentionally not guarded against another 401, so a failing retry surfaces to the caller rather than retrying indefinitely — matching the single-retry semantics of the existing non-throwing path, which is unchanged. The shared renewal logic is extracted into a private_retryWithNewTokenhelper used by both paths.Behavior is unchanged for: negotiate requests (never retried), clients without an access token factory, and non-401 errors (all propagate as before).
Testing
Added
AccessTokenHttpClient.test.tswith six tests:HttpError(the bug)HttpErrorAll SignalR TS client test suites that exercise this code path (
AccessTokenHttpClient,LongPollingTransport,ServerSentEventsTransport,HttpClient,HubConnection) pass locally with this change.Fixes #56494