[QUIC] Fix receive race. - #132287
Merged
Merged
Conversation
Member
Author
|
/azp list |
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Member
Author
|
/azp run runtime-libraries stress-http |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Contributor
|
Tagging subscribers to this area: @karelz, @dotnet/ncl |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts QuicStream.ReadAsync’s receive loop to be resilient to “stale” _receiveTcs wake-ups (i.e., a wake-up that occurs after buffered data was already consumed), preventing ReadAsync from returning 0 when no FIN has been received and avoiding premature stream disposal/abort scenarios.
Changes:
- Updates the
ReadAsyncloop condition to keep waiting when no bytes were copied and the internal receive buffer is empty, filtering out stale_receiveTcscompletions. - Threads through the “receive buffer empty” state from
ReceiveBuffers.CopyTo(...)to drive the new waiting behavior. - Updates the loop’s explanatory comments to match the new behavior.
This was referenced Aug 13, 2026
Member
Author
|
/ba-g failure is some pipeline error with publishing assets, unrelated |
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.
There's a race condition between
HandleEventReceiveandReadAsyncunblocking_receiveTcstwice.HandleEventReceivewill write data to the_receiveBuffersReadAsyncwill read them and unblock_receiveTcsand return to the callerReadAsync(with 0-byte read) will not copy anything and should wait for dataHandleEventReceivehappens and unblocks the_receiveTcsfor the data that were already returned to the user in the firstReadAsyncReadAsyncunblocks and returns and the caller interprets that we've received FIN and disposes the stream in good faith that the reading side is done, but it actually aborts insteadFixes #121567, #109121
This was tested locally with sleep in
HandleEventReceivethat previously 100% reproduced the issue.