Provide global back-pressure on mpsc::Sender::send #1671
Merged
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.
Previously the bounded mpsc channels don't provide back-pressure for every new cloned sender where the capacity check is bypassed. It's an issue when use it with combinators, like
buffer_unordered
and causes OOM eventually.There are great discussions in #984 about global vs local limits and more. From what I can see, it seems we all agree on the solution to call
poll_ready
inpoll_flush
so that it does the capacity check in everysend
call. The fix got merged into 0.1 in 4b0e217 and merged into 0.2 in 62827f1. But the latest 0.3 still has the issue. This PR is to fix that and also add tests to cover the back-pressure cases.