Skip to content

StreamBuffer pre-read body forwarding limited to 64 KiB #75

@usize

Description

@usize

Problem

The StreamBuffer pre-read in stream_buffer.rs consumes the downstream request body via read_request_body() so that body filters can promote headers before the request-phase pipeline runs (e.g. json_body_field extracting a model name).

After the pre-read, Pingora's body forwarding loop never calls request_body_filter because is_body_done() returns true. The pre-read body stored in ctx.pre_read_body is never drained to upstream.

Current Workaround

In #62 I added enable_retry_buffering() before the pre-read so that
Pingora's retry buffer captures the body data.

Pingora then uses get_retry_buffer() to replay the body to upstream via send_body_to_pipe.

However, Pingora's retry buffer is capped at 64 KiB via (BODY_BUF_LIMIT in pingora-core).

Bodies exceeding that limit are silently truncated and will not be forwarded to upstream.

Proposed Fix

Add an upstream Pingora API (e.g. set_preread_body()) that feeds Pingora's body forwarding loop without the 64 KiB retry buffer limit. Or, if we still need to enable retry buffering, ensure that we have a way to up the limit. @shaneutt mentioned that this can be resolved upstream.

Impact

Any StreamBuffer filter that processes request bodies larger than 64 KiB will silently drop the body when forwarding to upstream. Currently only json_body_field uses StreamBuffer, and its integration tests use start_header_echo_backend which does not read the request body, masking the issue.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

Status

Next

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions