This repository has been archived by the owner on Oct 17, 2022. It is now read-only.
fix: Make metered channel accounting take unused dropped Permits into account #849
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.
Context
We introduced metered channels in #682. Then we started using
mpsc::Permit
in #724 to implement composable backpressure.The issue
Permits increase the occupancy metric of their underlying channel when acquired. They decrease that occupancy when they are used to send an element that's received. They do not decrease this occupancy when the permit is dropped without being utilized to send anything.
This leads to the following graphs on precisely the three channels which in #724 were made to use permits:
For context, those channels have a bounded capacity of 1000 elements (due to the underlying use of a
tokio::mpsc::channel
). They show occupancy far above that, which constitutes the bug.The fix
We first introduce a (failing) test
test_reserve_and_drop
that shows the issue, and fix it by making permits from metered channels decrease the occupancy of their underlying channel when they are dropped without having sent an element.