Repository navigation
grpc: handle single-chunk bodies in grpc_web and grpc_http1_bridge - #49226
Conversation
Signed-off-by: wbpcode <[email protected]>
|
/retest |
agrawroh
left a comment
There was a problem hiding this comment.
💚 Approved. Both fixes take the right shape, and framing in place nicely drops the bridge's reliance on the filter manager forwarding data it added.
- ❓ #14516 kept a single-chunk local or direct reply whole on purpose, and the test this PR edits pinned that, so a configured reply over 16 KiB now arrives truncated.
- 💡 Behind a filter that buffers the body without streaming, such as the buffer filter,
datais the decoding buffer, so this 5-byte prepend turns a body within 5 bytes of the limit into a 413 where the old path let it through. - 💡 A chunked request with no chunks used to reach the upstream with no frame and now gets the empty message.
- 💡 A
Content-Length: 0request, the usual way to send an empty message, ends indecodeHeaders, so it still reaches the upstream with no frame. - 💡 These mocks can't show what the filter manager forwards, and no integration test enables
upgrade_protobuf_to_grpc. - 💡 The bridge holds the whole body but tells the filter manager it streams, so an over-limit body stalls until a timeout, or passes over the limit if it arrives in one read.
- 💡 The chunk that crosses 16 KiB and the final chunk are both buffered whole, so this overstates the bound.
- 💡 The other branch still appends the final chunk to the shared buffer before capping, so a final chunk that pushes it over the limit turns the error into a plain 500 without
grpc-status. - 💡 The cap applies to body bytes before percent-encoding, so the header can reach about 48 KiB.
- 🔄 When the request carries a
Content-Length, the bridge could read it before removing it, prepend the header to the first chunk and stream the body, asgrpc_http1_reverse_bridgedoes with its length check at the end. That fits a separate PR.
| output.move(*last_data); | ||
| // "encoding_buffer" is nullptr and we only have filled "last_data". A single chunk can be | ||
| // arbitrarily large too, so limit it the same way. | ||
| output.move(*last_data, MAX_BUFFERED_PLAINTEXT_LENGTH); |
There was a problem hiding this comment.
❓ #14516 kept a single-chunk local or direct reply whole on purpose, and the test this PR edits pinned that, so a configured reply over 16 KiB now arrives truncated. Should that sit behind a runtime guard? A paused HTTP/2 upstream's body can also reach us as one chunk, which argues for the cap.
| return Http::FilterDataStatus::Continue; | ||
| } | ||
|
|
||
| if (end_stream && !buffering_request_) { |
There was a problem hiding this comment.
💡 Behind a filter that buffers the body without streaming, such as the buffer filter, data is the decoding buffer, so this 5-byte prepend turns a body within 5 bytes of the limit into a 413 where the old path let it through. Could we keep the old path when &data == decoder_callbacks_->decodingBuffer()?
| } | ||
|
|
||
| if (end_stream && !buffering_request_) { | ||
| // The whole body arrived in this frame (possibly empty, e.g. a chunked request with no |
There was a problem hiding this comment.
💡 A chunked request with no chunks used to reach the upstream with no frame and now gets the empty message. Could the description call that a fix instead of "Behavior is unchanged", with a bug_fixes entry under a new grpc_http1_bridge area?
| {":path", "/v1/spotify.Concat/Concat"}}; | ||
| EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->decodeHeaders(request_headers, false)); | ||
|
|
||
| // E.g. a chunked HTTP/1.1 request with only the last chunk. |
There was a problem hiding this comment.
💡 A Content-Length: 0 request, the usual way to send an empty message, ends in decodeHeaders, so it still reaches the upstream with no frame. Could we add the frame there with addDecodedData once do_bridging_ and do_framing_ are set, as connect_grpc_bridge does? A follow-up is fine too.
| EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data, true)); | ||
| // The whole body in one frame is framed in place. | ||
| Buffer::OwnedImpl request_data("helloworld"); | ||
| EXPECT_CALL(decoder_callbacks_, addDecodedData(_, _)).Times(0); |
There was a problem hiding this comment.
💡 These mocks can't show what the filter manager forwards, and no integration test enables upgrade_protobuf_to_grpc. Could we add bridge integration cases that check the upstream bytes for a body, a chunked empty body and a body at the limit behind a buffer filter?
| EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->decodeHeaders(request_headers, false)); | ||
|
|
||
| Buffer::OwnedImpl buffered; | ||
| EXPECT_CALL(decoder_callbacks_, addDecodedData(_, true)) |
There was a problem hiding this comment.
💡 The bridge holds the whole body but tells the filter manager it streams, so an over-limit body stalls until a timeout, or passes over the limit if it arrives in one read. Could we skip addDecodedData on non-final frames and keep addDecodedData(data, true) on the last? Both then get a 413, which fits a follow-up with its own release note.
| // buffer filled with data. The value is arbitrarily chosen. This can be made configurable when it | ||
| // is required. | ||
| // This is the maximum length of the response body that is transformed into the grpc-message | ||
| // header value. It also limits how much body is buffered for that purpose. The value is arbitrarily |
There was a problem hiding this comment.
💡 The chunk that crosses 16 KiB and the final chunk are both buffered whole, so this overstates the bound. Could we reword it?
| // "encoding_buffer" is nullptr and we only have filled "last_data". | ||
| output.move(*last_data); | ||
| // "encoding_buffer" is nullptr and we only have filled "last_data". A single chunk can be | ||
| // arbitrarily large too, so limit it the same way. |
There was a problem hiding this comment.
💡 The other branch still appends the final chunk to the shared buffer before capping, so a final chunk that pushes it over the limit turns the error into a plain 500 without grpc-status. Could both branches take only the remaining room from the final chunk instead?
| @@ -0,0 +1,3 @@ | |||
| The gRPC-Web filter now limits the ``grpc-message`` built from a non-gRPC response body to 16 KiB | |||
There was a problem hiding this comment.
💡 The cap applies to body bytes before percent-encoding, so the header can reach about 48 KiB. Could we say it uses the first 16 KiB of the body?
Commit Message: grpc: handle single-chunk bodies in grpc_web and grpc_http1_bridge
Additional Description:
Both were found while reviewing #48660 but do not depend on it.
Risk Level: Low
Testing: Unit and integration tests updated/added.
Docs Changes: N/A
Release Notes: Added for grpc_web.