connection_limit: only decrement active connections when incremented#46108
Open
davidvo-lyft wants to merge 1 commit into
Open
connection_limit: only decrement active connections when incremented#46108davidvo-lyft wants to merge 1 commit into
davidvo-lyft wants to merge 1 commit into
Conversation
The connection limit filter unconditionally decremented the active_connections gauge and the internal connection counter on connection close, even when onNewConnection() never incremented them, e.g. when the filter is runtime disabled or an earlier filter in the chain stopped iteration. The unsigned counters underflowed, causing the gauge to report huge values and all subsequent connections to be wrongly rejected as over the limit. Track whether this filter instance incremented the accounting and only decrement in that case. Adds regression tests for both scenarios and a changelog entry. Fixes envoyproxy#22127. Signed-off-by: David Vo <davidvo@lyft.com>
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.
Commit Message: connection_limit: only decrement active connections when incremented
Additional Description:
The connection limit network filter incremented the active connection gauge and the internal
connection counter in
onNewConnection(), butonEvent()decremented them on every close event,including cases where
onNewConnection()never incremented: the filter being runtime disabled(early return before the increment) or an earlier filter in the chain stopping iteration so
onNewConnection()never ran. The unguarded decrement then underflowed the unsigned counter andtripped
ASSERT(connections_ > 0)in debug builds, and in release builds it permanentlyundercounted active connections, wrongly rejecting future connections once the limit was reached.
This tracks a
bool is_incremented_per filter instance (mirroring the existingis_rejected_)and only decrements when the increment actually happened, so the accounting is symmetric across
every lifecycle path (accepted, rejected, runtime disabled, chain stopped). This is the remedy the
triaging maintainer prescribed in the issue.
Risk Level: Low (small bug fix in one filter, no config or API change, behavior changes only on
the previously broken path).
Testing: Added
ConnectionLimitFilterTest.CloseWithoutOnNewConnectionandRuntimeDisabledCloseDoesNotDecrement. Both abort onmainatASSERT(connections_ > 0)and passafter the fix. The full
//test/extensions/filters/network/connection_limit:connection_limit_testtarget (7 tests) passes locally in the CI docker image (clang).
check_formatandcheck_spelling_pedanticpass.Docs Changes: N/A
Release Notes:
changelogs/current/bug_fixes/connection_limit__only-decrement-active-connections-when-incremented.rstPlatform Specific Features: N/A
Fixes #22127
Generative AI disclosure: This change was developed with AI assistance (Claude Code). I have
reviewed and understand every line, the connection lifecycle reasoning behind each decrement path,
and the test methodology, and I take full ownership of the submission and of addressing review
feedback.