Repository navigation
Description
ConnectionH1::retry_buffer (introduced by #1442) is a plain Vec on the global allocator, outside sozu's buffer Pool. It is not a leak and it is not unbounded — but it is unaccounted, and the bound it does have is an accident of a different knob.
Filed as a deliberate follow-up rather than widened into #1442; the analysis below comes from implementing and reviewing that changeset.
The actual bound, which is not the one you would guess
A capture can only exist on a live stream, and Stream::new takes exactly two pool.checkout() calls. So captures are transitively bounded at (max_buffers / 2) × buffer_size.
At defaults — max_buffers 1000, buffer_size 16393 — that is ≈8 MB, not the ~160 MB a naive max_connections × buffer_size estimate gives. That estimate is wrong because it assumes 10000 concurrent requests, which max_buffers 1000 does not permit; reaching 160 MB needs max_buffers raised to ~20000.
So the true statement is: pooled idempotent traffic costs up to +50% on the pool's own worst-case footprint, in memory no max_buffers accounting can see. The capture also grows to the actual request size rather than to the budget, so the typical one is a few hundred bytes.
Why moving it into the Pool is the wrong fix
max_buffers defaults to 1000 against max_connections 10000 — deliberately oversubscribed 10:1 and rationed by parked_on_buffer_pressure / MaxBuffers.
Putting captures in the pool converts today's graceful degradation — "we decline to retry, the client gets the 502 it would have got anyway" — into "we refuse new sessions with 503 and park frontends." That is a strictly worse failure mode under the exact memory pressure the change is meant to manage, and it would need new max_buffers sizing guidance in doc/configure.md to avoid surprising every existing deployment.
The shape that preserves the good degradation
A global capture counter with a ceiling that disarms capture past it. Past the ceiling, arm_upstream_replay simply does not install a buffer; the request proceeds un-replayable and a stale pooled upstream yields the same 502 it yields today. Nothing is refused, nothing parks, and the memory is bounded by a number an operator can see and set.
That also gives the accounting the current design lacks: a gauge of armed captures and a counter of captures declined for budget are both meaningful operational signals, where "invisible heap proportional to a fraction of the pool" is not.
Asked for
- Decide whether the ≈8 MB default worst case warrants a bound at all, or whether documenting it in
doc/configure.mdbesidemax_buffersis sufficient. Document it either way — the current situation is that the memory exists and no document mentions it. - If a bound is wanted, implement the disarm-past-ceiling shape rather than pool allocation, and emit the two metrics above.
- Whatever is chosen, state the transitive
(max_buffers / 2) × buffer_sizerelationship somewhere an operator sizingmax_bufferswill find it. It is not obvious, and the obvious estimate is wrong by 20×.
Do not fix this by shrinking the capture budget. The budget is what makes the replay possible at all, and buffer_size is already the bound on a single request.
Activity
FlorentinDUBOIS commentedon Sep 23, 2026
Decision: bound it, with the disarm-past-ceiling shape, plus both metrics and the documentation
Pool allocation is rejected for the reason set out above — it converts a graceful degradation
("we decline to retry, the client gets the 502 it would have got anyway") into session refusal with
503 and parked frontends, under exactly the memory pressure the bound exists to manage.
What to build:
arm_upstream_replayinstalls no buffer and the request proceeds un-replayable. Nothing isrefused, nothing parks.
invisible heap proportional to a fraction of the pool is not an operational signal; these are.
(max_buffers / 2) × buffer_sizerelationship stated indoc/configure.mdbesidemax_buffers, because the obvious estimate (max_connections × buffer_size) is wrong by a factorof 20 and an operator sizing
max_bufferswill not otherwise find it.The documentation is due regardless of the bound: today the memory exists and no document mentions
it.
fix(mux-h1): bound the stale-upstream replay captures and account for…
fix(mux-h1): bound the stale-upstream replay captures and account for…
fix(mux-h1): bound the stale-upstream replay captures and account for…