Avoid spurious wakeups when stream capacity is not available #661
+111
−33
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_capacity
returnsReady(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_inc
flag may be set.The sending task calls
send_data
and uses the entire allocatedcapacity, leaving the flag set. Next time
poll_capacity
returnsReady(Some(0))
.This change sets the flag and dispatches the wakeup event only in
cases when the effective capacity reported by
poll_capacity
actuallyincreases.