Refresh cached credentials after PreAuthenticate fails#101053
Merged
rzikm merged 9 commits intodotnet:mainfrom Apr 30, 2024
Merged
Refresh cached credentials after PreAuthenticate fails#101053rzikm merged 9 commits intodotnet:mainfrom
rzikm merged 9 commits intodotnet:mainfrom
Conversation
This was referenced Apr 15, 2024
This was referenced Apr 17, 2024
wfurt
reviewed
Apr 21, 2024
| NetEventSource.Info(pool.PreAuthCredentials, $"Pre-authentication credentials changed, removing Basic credential uri={preAuthCredentialUri}, username={preAuthCredential.UserName}"); | ||
| } | ||
| pool.PreAuthCredentials.Remove(preAuthCredentialUri!, BasicScheme); | ||
| } |
Member
There was a problem hiding this comment.
While we lock the PreAuthCredentials the logic leading to this can run in parallel, right? Do we have concurrency problem when Remove can throw? Perhaps use TryRemove?
Member
Author
There was a problem hiding this comment.
The method calls Dictionary<TKey, TValue>.Remove() internally, which does not throw if the key does not exist in the first place.
Member
Author
There was a problem hiding this comment.
But considering parallel requests, since we drop the lock between removing the creds and adding new ones, there may be some weird behavior if a parallel request starts when in-between. So I will move the removal to the same lock scope.
wfurt
reviewed
Apr 21, 2024
src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.BasicAuth.cs
Show resolved
Hide resolved
This was referenced Apr 22, 2024
This was referenced Apr 22, 2024
This was referenced Apr 25, 2024
Closed
This was referenced Apr 25, 2024
Closed
Member
Author
|
Test failures are known (HTTP3 tests which were addressed since the pipeline has run). |
michaelgsharp
pushed a commit
to michaelgsharp/runtime
that referenced
this pull request
May 9, 2024
* Support refreshing credentials in pre-auth cache * Fix minor bug in CredentialCache * Add unit test * Fix tests * Fix tests attempt 2 * Merge two lock statements. * Fix build
Ruihan-Yin
pushed a commit
to Ruihan-Yin/runtime
that referenced
this pull request
May 30, 2024
* Support refreshing credentials in pre-auth cache * Fix minor bug in CredentialCache * Add unit test * Fix tests * Fix tests attempt 2 * Merge two lock statements. * Fix build
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Fixes #93340.
This PR adds logic which, after Pre-Authenticated request fails with 401, checks whether the user supplied creentials are different from the cached ones, and if so, replaces the old (stale) creds with the new ones.
An implementational obstacle was removing the old creds from the preauth cache, because of insufficient API surface of CredentialCache. Therefore: