Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the OAuth2 introspection handler to avoid “poisoning” concurrent requests with a faulted in-flight introspection task, and adds regression tests for the concurrent fault/retry behavior.
Changes:
- Add fault-handling around the in-flight introspection task so a faulted shared task is evicted and the request retries.
- Add new tests covering two concurrent requests where the first introspection attempt faults (with both retry-success and persistent-failure cases).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| introspection/src/AspNetCore.Authentication.OAuth2Introspection/OAuth2IntrospectionHandler.cs | Adds catch/evict/retry behavior when the shared in-flight introspection task faults. |
| introspection/test/AspNetCore.Authentication.OAuth2Introspection.Tests/Introspection.cs | Adds concurrency tests for faulted introspection + retry semantics. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+116
to
+128
| try | ||
| { | ||
| response = await IntrospectionDictionary | ||
| .GetOrAdd(token, GetTokenIntrospectionResponseLazy) | ||
| .Value; | ||
| } | ||
| catch | ||
| { | ||
| // The shared task faulted (e.g. timeout, cancellation, network error). | ||
| // Evict the faulted entry so future requests start fresh, then retry | ||
| // once with a direct call — bypassing the dictionary — so this request | ||
| // is not affected by another request's failure. | ||
| IntrospectionDictionary.TryRemove(token, out _); |
Comment on lines
+190
to
+212
| // Signal R2 it can proceed, then wait for R2 to be waiting on the dictionary entry | ||
| waitForSecondRequestToStart.WaitOne(); | ||
| waitForFirstIntrospectionToStart.Set(); | ||
| await Task.Delay(200); // wait for R2 to reach IntrospectionDictionary | ||
| throw new HttpRequestException("Simulated network error"); | ||
| } | ||
| // Subsequent calls (retries) succeed normally | ||
| }; | ||
| }, handler); | ||
|
|
||
| var client1 = new HttpClient(messageHandler); | ||
| var request1 = Task.Run(async () => | ||
| { | ||
| client1.SetBearerToken(token); | ||
| return await client1.GetAsync("http://test"); | ||
| }); | ||
|
|
||
| var client2 = new HttpClient(messageHandler); | ||
| var request2 = Task.Run(async () => | ||
| { | ||
| waitForSecondRequestToStart.Set(); | ||
| waitForFirstIntrospectionToStart.WaitOne(); | ||
| client2.SetBearerToken(token); |
Comment on lines
+245
to
+249
| // Signal R2, wait for it to reach the dictionary, then fault | ||
| waitForSecondRequestToStart.WaitOne(); | ||
| waitForFirstIntrospectionToStart.Set(); | ||
| await Task.Delay(200); // wait for R2 to reach IntrospectionDictionary | ||
| } |
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.
Summary
Fixes #281