Repository navigation
test(mux): read the gauge the three active_requests e2e tests are named after - #1541
Merged
Merged
Conversation
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 25, 2026 21:20
FlorentinDUBOIS
force-pushed
the
test/mux-active-requests-gauge
branch
from
September 25, 2026 22:01
8e33844 to
eecf0b0
Compare
…ed after
`e2e/src/tests/mux_tests.rs` carried three tests named for `http.active_requests`
under a header advertising "P0: close() stream cleanup (http.active_requests gauge
leak)". None of the three read the gauge: the idle-timeout one opened five
connections, collected their 408s and asserted that a LATER request answered 200,
which holds identically with or without an underflow.
They could not have been written in that shape either. `AggregatedMetric::update`
clamps a negative `GaugeAdd` to exactly 0 — correctly, since a `clear()` under
live traffic can drive a paired decrement below a fresh baseline — so from a zero
baseline a parasitic `-1` reads 0 and so does a balanced request.
Move the baseline instead. `http.active_requests` is per worker process, so
`hold_one_request_in_flight` puts one legitimate request in flight on its own
connection, held at the backend between `receive` and `send`, and proves the gauge
reads 1. Each scenario then runs on other connections and must leave the gauge at
exactly 1; a parasitic decrement shows up as 0. Releasing the held request takes it
to 0 and pins the decrement a charged stream does owe.
`expect_active_requests_h1` takes a single sample rather than polling: a poll for a
value the gauge already holds returns on its first iteration without observing the
scenario at all. `raw_read_until_eof` earns that single sample — a stream's access
log, and with it the `-1`, is emitted before sozu shuts the frontend socket down —
and reports a deadline as an error instead of folding it into the bytes read.
`query_proxy_gauge` and `await_active_requests_h1` are reused unchanged, including
their refusal to fold `None` into `0`.
`setup_short_timeout_test` now shortens `request_timeout` and nothing else: it is
the timeout a frontend is armed with before its first request links, while a
two-second `front_timeout` or `back_timeout` would answer the held request 504 and
emit a perfectly legitimate `-1`, zeroing the gauge for a correct proxy.
Seen red on otherwise unmodified production code, and the reds are two, not three.
Dropping the `if self.request_counted` condition in `Stream::generate_access_log`
reddens the idle-timeout and malformed tests together (`wanted 1, sample Some(0)`,
1 passed / 2 failed): both reach the same access log on the same never-charged
stream, and there is no second guard between "no +1" and "no -1" to remove.
Deleting the `kawa::StatusLine::Response { code: 100, .. }` arm in
`ConnectionH1::writable` reddens the 100-Continue test alone (`wanted 2, sample
Some(1)`, 2 passed / 1 failed), observable only between the 100 and the 200.
Removing the `self.request_counted = false;` clear reddens nothing by the gauge —
it trips its own `debug_assert!` first — and no end-to-end test can reach that
guard, since no production path calls `generate_access_log` twice on one stream.
This changeset is test-only and no production file changed.
Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
force-pushed
the
test/mux-active-requests-gauge
branch
from
September 25, 2026 23:39
eecf0b0 to
674c3b3
Compare
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.
e2e/src/tests/mux_tests.rscarried three tests named afterhttp.active_requests— "H1 idletimeout does not underflow", "H1 malformed request does not underflow", "H1 100 Continue does not
double-decrement" — under a file header advertising "P0: close() stream cleanup
(http.active_requests gauge leak)". None of the three read the gauge. The first opened five
connections, waited out their 408s, then asserted that a later request answered 200 — an assertion
that holds identically with or without an underflow.
Why they could not have been written in that shape
AggregatedMetric::updateclamps a negativeGaugeAddto exactly 0 and logs anerror!. The clampis deliberate and correct: a
clear()under live traffic can legitimately drive a paired decrementbelow a freshly reset baseline. Its consequence here is that "does not underflow" is not
observable from the gauge's value when the gauge starts at zero.
The property the three tests were named for is one their shape could not express. They were written
for a change whose regression they therefore never witnessed.
The shape that makes it observable
http.active_requestsis per worker process, not per connection.hold_one_request_in_flightputsONE legitimate request in flight on its own connection — held at the backend between
backend.receiveandbackend.send, an ordering guarantee rather than a sleep — and proves thegauge reads exactly
1. The scenario under test then runs on other connections, and the assertionis that the gauge still reads exactly
1. A parasitic decrement takes it to0, which isobservable. Releasing the held request afterwards takes the gauge to
0and pins the decrement acharged stream does owe.
Built on #1537's tooling rather than beside it:
query_proxy_gaugeandawait_active_requests_h1are reused as they are, including the property that
Noneis never folded into0— "the key doesnot exist" and "the gauge reads zero" stay two observations, which is exactly what the three hollow
tests could never distinguish. Two helpers are added:
expect_active_requests_h1takes a SINGLE sample, deliberately not a poll. A poll for a value thegauge already holds returns on its first iteration without ever observing the scenario — the
vacuity this changeset is about.
raw_read_until_eofis the barrier that earns that single sample. A stream's access log, and withit the
-1, is emitted before sozu shuts the frontend socket down, so a client that has read EOFhas already been passed by every decrement that connection can emit. A deadline is reported as an
error rather than folded into the bytes read.
setup_short_timeout_testnow shortensrequest_timeoutand nothing else. Which one is shortened isload-bearing, not frugality:
request_timeoutis the timeout a frontend is armed with before itsfirst request links, so it alone decides how fast a silent connection collects its 408, while a
two-second
front_timeoutorback_timeoutwould answer the held request 504 and emit aperfectly legitimate
-1. The gauge would then read zero for a correct proxy, which isindistinguishable from the underflow the test exists to catch.
The reds — there are two, not three
Each was obtained by removing one production guard on otherwise unmodified code. The production diff
of this branch is empty:
git diff --name-onlyisCHANGELOG.md,doc/testing.mdande2e/src/tests/mux_tests.rs.Dropping the
if self.request_countedcondition inStream::generate_access_log(
lib/src/protocol/mux/stream.rs), leavingevents[0] = Some(MetricEvent::ActiveRequestFinished);and
self.request_counted = false;unconditional:The idle-timeout and malformed tests fall together, and that is the structure of the code rather
than a shortcut. Both scenarios reach the same access log on the same never-charged stream, and
there is no second guard between "no
+1" and "no-1" to remove — two scenarios through oneguard, not two guards. No third distinct red was invented to disguise it.
Deleting the
kawa::StatusLine::Response { code: 100, .. }arm inConnectionH1::writable(
lib/src/protocol/mux/h1.rs), so a 100 falls through to the generic completion path:That red is isolated, and it is observable only between the 100 and the 200: once the final
response has landed the gauge is back at the held baseline in the correct tree and in the mutated
one, because
request_countedmakes a second access log harmless. So the test samples while theclient holds its 100 and the backend still holds the 200.
A third candidate was measured and rejected. Removing the
self.request_counted = false;clearreddens nothing by the gauge: it trips its own
debug_assert!at the same site first(
generate_access_log must leave request_counted false (gauge-underflow guard)), killing the workerin all three tests. It could not have reddened them by the gauge anyway — no production path calls
generate_access_logtwice on one stream, because the completion path clearsmetrics.startthrough
stream.metrics.reset()andMux::closeskips every stream whosemetrics.startisNone. The 100-Continue test's doc comment records that, so its closing assertion is not read ascovering an idempotency guard no end-to-end test can reach.
After each red the mutated file was restored from
git show HEAD:<path>and compared byte for byteagainst a pre-mutation copy with
cmp, and the three tests were re-run green.Also
The file header no longer advertises a property it did not cover, and
doc/testing.md's gaugesection gains the held-baseline technique together with its two rules — hold the baseline longer
than the scenario, and sample once after a barrier instead of polling.
Closes #1535
Signed-off-by: Florentin Dubois [email protected]