connection_manager: replace usize counter with Semaphore RAII permit#2350
Merged
amankrx merged 2 commits intoMay 20, 2026
Merged
Conversation
palfrey
requested changes
May 20, 2026
Member
palfrey
left a comment
There was a problem hiding this comment.
Minor naming item, otherwise good
Collaborator
|
I like the use of a permit here in place of a counter. |
220648d to
1207a0f
Compare
palfrey
approved these changes
May 20, 2026
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.
Description
Production worker pods were OOMKilled (exit 137) after the ConnectionManager's available_connections: usize counter underflowed to ~u64::MAX while waiting_connections climbed unbounded. The manual decrement-on-issue / increment-on-Dropped accounting balances on paper, but a leak path was occasionally missing a Dropped delivery during tonic transport errors and task aborts.
Switch to Arc with OwnedSemaphorePermit on the Connection. RAII makes leakage structurally impossible: every Drop path (panic, abort, dropped oneshot receiver, transport error) releases the permit exactly once.
Fixes # (issue)
Type of change
Please delete options that aren't relevant.
How Has This Been Tested?
Added tests and tested it in an actual running environment.
Checklist
bazel test //...passes locallygit amendsee some docsThis change is