Skip to content

core: allow a session to widen its retry buffer - #28

Merged
pigri merged 1 commit into
mainfrom
feat/retry-buffer-limit
Sep 8, 2026
Merged

pigri merged 1 commit into
mainfrom
feat/retry-buffer-limit

Conversation

@pigri

@pigri pigri commented Sep 8, 2026

Copy link
Copy Markdown

Why

enable_retry_buffering fixes the retry buffer at BODY_BUF_LIMIT (64 KB), and get_retry_buffer returns None once that is exceeded. A request body larger than 64 KB therefore cannot be replayed.

Raising the constant is not a workable alternative: the proxy calls enable_retry_buffering for every request, so a larger default would make every deployment start retaining request bodies up to the new ceiling.

What

enable_retry_buffering_with_limit(limit) -> bool, alongside the existing call. It creates the buffer at the requested capacity, or widens one that has not started filling. The 64 KB default is untouched.

The boolean is the important part. Widening after bytes have landed cannot recover what was already dropped, so a buffer that holds data — or one already truncated — refuses the change and returns false, rather than claiming to hold a whole body when it holds a prefix. A caller that intends to read a body and rely on replaying it must check this and fall back to streaming when it is false.

Added on v1, v2 and subrequest sessions plus the Session enum, and defaulted on the custom Session trait so existing implementors are unaffected.

Motivating case

A proxy that inspects a request body before letting it reach the upstream has to read the body itself. Without a replayable buffer, the upstream request goes out with a Content-Length it never satisfies — the connection aborts with PrematureBodyEnd and the upload hangs until it times out.

Testing

Three unit tests on FixedBuffer: a raised capacity retains a body the default would truncate; a resize is refused once data has landed; a resize is refused after truncation and the buffer stays truncated.

cargo test -p pingora-core --lib passes, cargo fmt --check and cargo clippy -p pingora-core are clean.

No behaviour change for any existing caller — nothing calls the new method in this PR.

`enable_retry_buffering` fixes the buffer at BODY_BUF_LIMIT (64 KB), and
`get_retry_buffer` returns None once that is exceeded, so a body larger
than 64 KB cannot be replayed. The proxy enables retry buffering for
every request, so raising the constant is not an option either: every
deployment would start retaining request bodies up to the new ceiling.

Add `enable_retry_buffering_with_limit(limit) -> bool` alongside it, so a
caller can opt individual requests into full retention and leave the
default alone. It creates the buffer at the requested capacity, or widens
one that has not started filling.

The return value matters. Widening after bytes have landed cannot recover
what was already dropped, so a buffer with data (or one already
truncated) refuses the change and reports false rather than claiming to
hold a whole body it only holds a prefix of. Callers that intend to read
a body and rely on replaying it must check this and fall back to
streaming when it is false.

The motivating case is a proxy that inspects a request body before
letting it reach the upstream: it has to read the body itself, and
without a replayable buffer the upstream request would be sent with a
Content-Length it never satisfies.

Defaulted on the custom `Session` trait so existing implementors are
unaffected.
@pigri
pigri force-pushed the feat/retry-buffer-limit branch from 22ad3ad to 57b39b5 Compare September 8, 2026 11:42
@pigri
pigri merged commit b3fcf07 into main Sep 8, 2026
4 checks passed
@pigri
pigri deleted the feat/retry-buffer-limit branch September 8, 2026 11:56
@linear-code

linear-code Bot commented Sep 8, 2026

Copy link
Copy Markdown

MAN-22

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.

1 participant