Avoid spurious wakeups when stream capacity is not available#661
Merged
seanmonstar merged 2 commits intohyperium:masterfrom Feb 20, 2023
Merged
Avoid spurious wakeups when stream capacity is not available#661seanmonstar merged 2 commits intohyperium:masterfrom
seanmonstar merged 2 commits intohyperium:masterfrom
Conversation
Fixes hyperium#628 Sometimes `poll_capacity` returns `Ready(Some(0))` - in which case caller will have no way to wait for the stream capacity to become available. The previous attempt on the fix has addressed only a part of the problem. The root cause - in a nutshell - is the race condition between the application tasks that performs stream I/O and the task that serves the underlying HTTP/2 connection. The application thread that is about to send data calls `reserve_capacity/poll_capacity`, is provided with some send capacity and proceeds to `send_data`. Meanwhile the service thread may send some buffered data and/or receive some window updates - either way the stream's effective allocated send capacity may not change, but, since the capacity still available, `send_capacity_inc` flag may be set. The sending task calls `send_data` and uses the entire allocated capacity, leaving the flag set. Next time `poll_capacity` returns `Ready(Some(0))`. This change sets the flag and dispatches the wakeup event only in cases when the effective capacity reported by `poll_capacity` actually increases.
fc5ec42 to
1f6464e
Compare
seanmonstar
approved these changes
Feb 20, 2023
Member
seanmonstar
left a comment
There was a problem hiding this comment.
Excellent work, thank you!
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.
Fixes #628
Sometimes
poll_capacityreturnsReady(Some(0))- in which casecaller will have no way to wait for the stream capacity to become available.
The previous attempt on the fix has addressed only a part of the problem.
The root cause - in a nutshell - is the race condition between the
application tasks that performs stream I/O and the task that serves
the underlying HTTP/2 connection. The application thread that is about
to send data calls
reserve_capacity/poll_capacity, is providedwith some send capacity and proceeds to
send_data.Meanwhile the service thread may send some buffered data and/or
receive some window updates - either way the stream's effective
allocated send capacity may not change, but, since the capacity still
available,
send_capacity_incflag may be set.The sending task calls
send_dataand uses the entire allocatedcapacity, leaving the flag set. Next time
poll_capacityreturnsReady(Some(0)).This change sets the flag and dispatches the wakeup event only in
cases when the effective capacity reported by
poll_capacityactuallyincreases.