StatsAccessLogger: fixes connection gauge underflow crashes when decrementing metrics after Scope evictions. #43812
Mobile/CC (success)
Check has finished
Details
Check run finished (success ✔️)
The check run can be viewed here:
Mobile/CC (pr/43812/main@9592318)
Check started by
Request (pr/43812/main@9592318)
@TAOXUY
9592318 #43812
merge main@d3e80e6
StatsAccessLogger: fixes connection gauge underflow crashes when decrementing metrics after Scope evictions.
Description: Fixes connection gauge underflow crashes in the Stats Access Logger when decrementing metrics after Scope evictions.
The original code correctly attempted to prevent "zombie" gauges by re-resolving metrics against the central store (via scope_->gaugeFromStatNameWithTags) during request destruction. However, it tried to reconstruct the gauge's identity using gauge_->tagExtractedStatName(). This failed because dynamic access-log tags (like %REQUEST_HEADER(...)%) are not registered with Envoy's global extractors. The extraction process returned a mangled base name and empty tags, forcing Scope to create a new 0-valued gauge. Subtracting 1 from it immediately crashed Envoy with a counter underflow.
Fix: we will keep the gauge in the scope cache if it is non-zero
Risk Level: Low
Testing: Added StatsAccessLogIntegrationTest.ActiveRequestsGaugeScopeEviction, which synthetically forces an asynchronous scope eviction while a connection is still inflight. Verified that the gauge successfully decrements to 0 in the central store identically to a normal request finish.
Docs: NA
Release: NA
Platform Specific Features: no
Benchmark result on single AddSubtract
![]()
Environment
Request variables
| Key | Value |
|---|---|
| ref | 02e5708 |
| sha | 9592318 |
| pr | 43812 |
| base-sha | d3e80e6 |
| actor | |
| message | StatsAccessLogger: fixes connection gauge underflow crashes when decrementing metrics after Scope evictions.... |
| started | 1774479565.179137 |
| target-branch | main |
| trusted | false |
Build image
Container image/s (as used in this CI run)
| Key | Value |
|---|---|
| default | docker.io/envoyproxy/envoy-build:86873047235e9b8232df989a5999b9bebf9db69c |
| mobile | docker.io/envoyproxy/envoy-build:mobile-86873047235e9b8232df989a5999b9bebf9db69c |
Version
Envoy version (as used in this CI run)
| Key | Value |
|---|---|
| major | 1 |
| minor | 38 |
| patch | 0 |
| dev | true |
