Skip to content

connection_limit: only decrement active connections when incremented#46108

Open
davidvo-lyft wants to merge 1 commit into
envoyproxy:mainfrom
davidvo-lyft:davidvo/22127-connection-limit-decrement
Open

connection_limit: only decrement active connections when incremented#46108
davidvo-lyft wants to merge 1 commit into
envoyproxy:mainfrom
davidvo-lyft:davidvo/22127-connection-limit-decrement

Conversation

@davidvo-lyft

Copy link
Copy Markdown
Contributor

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(), but onEvent() 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 and
tripped ASSERT(connections_ > 0) in debug builds, and in release builds it permanently
undercounted active connections, wrongly rejecting future connections once the limit was reached.
This tracks a bool is_incremented_ per filter instance (mirroring the existing is_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.CloseWithoutOnNewConnection and
RuntimeDisabledCloseDoesNotDecrement. Both abort on main at ASSERT(connections_ > 0) and pass
after the fix. The full //test/extensions/filters/network/connection_limit:connection_limit_test
target (7 tests) passes locally in the CI docker image (clang). check_format and
check_spelling_pedantic pass.

Docs Changes: N/A

Release Notes: changelogs/current/bug_fixes/connection_limit__only-decrement-active-connections-when-incremented.rst

Platform 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.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Connection Limit filter reporting 18 quintillion active connections

1 participant