-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix race condition when cancelling pending HTTP connection attempts #110744
base: main
Are you sure you want to change the base?
Conversation
/azp run runtime-libraries-coreclr outerloop |
Azure Pipelines successfully started running 1 pipeline(s). |
/backport to release/9.0-staging |
Started backporting to release/9.0-staging: https://github.com/dotnet/runtime/actions/runs/12364986878 |
response.Dispose(); | ||
BlocklistAuthority(connection.Authority); | ||
continue; | ||
http3ConnectionWaiter?.CancelIfNecessary(this, cancellationToken.IsCancellationRequested); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With HTTP 1 and 2, we do this here instead:
Lines 562 to 563 in ce9dd2a
http11ConnectionWaiter?.CancelIfNecessary(this, cancellationToken.IsCancellationRequested); | |
http2ConnectionWaiter?.CancelIfNecessary(this, cancellationToken.IsCancellationRequested); |
.../System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectionPool/HttpConnectionPool.cs
Outdated
Show resolved
Hide resolved
.../System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectionPool/HttpConnectionPool.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM modulo nitpicking comments above.
Fixes #110598
There's a race condition here where if the initiating request completes right away, before we're able to set the
CTS
inInjectNewHttp11ConnectionAsync
, we'll never set the timeout.runtime/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectionPool/HttpConnectionWaiter.cs
Lines 78 to 93 in c969265
runtime/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectionPool/HttpConnectionPool.Http1.cs
Lines 256 to 263 in c969265
It's easy to reproduce if you add a delay between the
Yield
and assigning thects
, while failing the request.The test I added was 100% deterministic if I added the delay, or increased the
Parallel
count from 100 to 1000, but that takes too long to run for CI.The HTTP/3 change is just adding a try/finally to signal the waiter, looks like we missed that in #101531.
Diff without whitespace changes