core: allow a session to widen its retry buffer - #28
Merged
Merged
Conversation
`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
force-pushed
the
feat/retry-buffer-limit
branch
from
September 8, 2026 11:42
22ad3ad to
57b39b5
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.
Why
enable_retry_bufferingfixes the retry buffer atBODY_BUF_LIMIT(64 KB), andget_retry_bufferreturnsNoneonce 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_bufferingfor 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 isfalse.Added on
v1,v2andsubrequestsessions plus theSessionenum, and defaulted on the customSessiontrait 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-Lengthit never satisfies — the connection aborts withPrematureBodyEndand 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 --libpasses,cargo fmt --checkandcargo clippy -p pingora-coreare clean.No behaviour change for any existing caller — nothing calls the new method in this PR.