Skip to content

retry_buffer captures are bounded only transitively by max_buffers, and no accounting sees them #1450

Closed

Description

@FlorentinDUBOIS

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

  1. Decide whether the ≈8 MB default worst case warrants a bound at all, or whether documenting it in doc/configure.md beside max_buffers is sufficient. Document it either way — the current situation is that the memory exists and no document mentions it.
  2. If a bound is wanted, implement the disarm-past-ceiling shape rather than pool allocation, and emit the two metrics above.
  3. Whatever is chosen, state the transitive (max_buffers / 2) × buffer_size relationship somewhere an operator sizing max_buffers will 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

  1. FlorentinDUBOIS commented on Sep 23, 2026

    @FlorentinDUBOIS
    CollaboratorAuthor

    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:

    1. A global capture counter with a ceiling that disarms capture past it: beyond the ceiling,
      arm_upstream_replay installs no buffer and the request proceeds un-replayable. Nothing is
      refused, nothing parks.
    2. Both metrics — a gauge of armed captures, and a counter of captures declined for budget. An
      invisible heap proportional to a fraction of the pool is not an operational signal; these are.
    3. The transitive (max_buffers / 2) × buffer_size relationship stated in doc/configure.md beside
      max_buffers, because the obvious estimate (max_connections × buffer_size) is wrong by a factor
      of 20 and an operator sizing max_buffers will not otherwise find it.

    The documentation is due regardless of the bound: today the memory exists and no document mentions
    it.

  2. added 2 commits that reference this issue on Sep 23, 2026
    9a2ebcd
    18c3e00
  3. added a commit that references this issue on Sep 23, 2026
    1b0c7cc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions