Repository navigation
Conversation
…overflow Signed-off-by: wbpcode <[email protected]>
agrawroh
left a comment
There was a problem hiding this comment.
🚫 Suggested Fixes. Draining at give-up is the right time to release the kept body, and it stops a filter that buffers after the router gives up from stacking on it into a 413 or a stalled read.
- 🚨 This drains the shared buffer, which can also hold an earlier filter's paused frame.
- 💡 Async client streams keep their body anyway, because
AsyncStreamImplignores themodifyDecodingBuffer()callback, so an ext_proc or gRPC access log stream with a retry policy keeps up to 64 KiB by default after the give-up. - 💡 On its own the kept body never crosses the high watermark, so dropping it doesn't resume a paused read.
- 💡 Neither test hands the router a frame while the decoding buffer holds another filter's bytes.
- 💡 The 40 kept bytes go upstream through a nice mock with no expectation, so this passes even if they're never sent.
- 🔄 The kept body also stays for the rest of the stream when retries end at the final upstream headers, so a POST followed by a long streaming response holds it throughout. Could we track releasing it once nothing can replay it, including an encoder filter that recreates the stream, with the same ownership check?
| // Nothing reads the kept body once retries and redirects are given up, so drop it to release | ||
| // its buffer accounting. Skip it if the current frame is the decoding buffer itself, since the | ||
| // frame still has to be forwarded upstream. | ||
| if (decoding_buffer != nullptr && decoding_buffer != &data) { |
There was a problem hiding this comment.
🚨 This drains the shared buffer, which can also hold an earlier filter's paused frame. With Lua calling httpCall() in bodyChunks() ahead of bandwidth_limit on a retry route, Lua's parked chunk is dropped when the injected chunk overflows, and without a content-length the request still succeeds. Could we drain only when the buffer holds just the bytes the router added?
There was a problem hiding this comment.
It's impossible with a shared buffer. This is why we need the per-filter-buffer.
And note, if the httpCall() in bodyChunks() ahead of bandwidth_limit (use inject API), and the retry is enabled, the buffer is broken anyway. The injected data will back to the shared buffer, and filter after Lua will see it again.
Nightware.
My suggestion is holding this PR, until the per filer buffer is down. And only do it in the per filter buffer mode.
There was a problem hiding this comment.
Agreed it's broken at base once the router keeps bytes before or during the pause, but when its next frame overflows, main forwards the paused frame and this drain drops it. Holding for per-filter buffers works for us, since that mode kept every byte with this drain, as a router-bytes check did for the paused frame in shared mode.
| // its buffer accounting. Skip it if the current frame is the decoding buffer itself, since the | ||
| // frame still has to be forwarded upstream. | ||
| if (decoding_buffer != nullptr && decoding_buffer != &data) { | ||
| callbacks_->modifyDecodingBuffer( |
There was a problem hiding this comment.
💡 Async client streams keep their body anyway, because AsyncStreamImpl ignores the modifyDecodingBuffer() callback, so an ext_proc or gRPC access log stream with a retry policy keeps up to 64 KiB by default after the give-up. Could it run the callback on buffered_body_ when it's set, or the release note say this covers downstream streams only?
There was a problem hiding this comment.
This still applies under either fix. Only the router writes buffered_body_, so AsyncStreamImpl can run the callback on it whenever it's set, and a mode callback there would need to report it as the router's own.
| @@ -0,0 +1,3 @@ | |||
| The router now drops the request body it kept for retries or internal redirects once the body exceeds | |||
| the retry buffer limit and retries/redirects are given up, instead of holding it until the stream | |||
| ends. This releases the memory early and lets the downstream read resume sooner. | |||
There was a problem hiding this comment.
💡 On its own the kept body never crosses the high watermark, so dropping it doesn't resume a paused read. It stops a filter that buffers after the router gives up from stacking on it into a 413 or a stall. Could the note and the description say that?
There was a problem hiding this comment.
In per-filter mode a parked frame counts with the router's kept bytes toward one stream total, so when a watermark pause pushed it over the limit and the kept bytes alone exceed half, the drain is what resumes reads. With either fix, could the note scope that claim to per-filter mode and name its guard?
| prod_filter.onDestroy(); | ||
| } | ||
|
|
||
| TEST_F(RouterTest, RetryBufferOverflowDrainsKeptBodyWithActiveUpstream) { |
There was a problem hiding this comment.
💡 Neither test hands the router a frame while the decoding buffer holds another filter's bytes. Could we add that case, expecting no drain, plus integration tests where a filter before the router buffers after the give-up and where bandwidth_limit injects past a paused filter, checking the exact upstream body on HTTP/1 and on HTTP/2 with a route limit?
There was a problem hiding this comment.
With either fix, could integration tests check the exact upstream body when a filter injects an earlier frame as the router's first while one before it parks a later frame, on HTTP/2 in both modes, and when a filter parks past the limit on HTTP/1 in per-filter mode, where reads must resume? HTTP/1 merged the first case's writes for us.
| // Kept for a retry: within the limit. | ||
| Buffer::OwnedImpl buf1(std::string(40, 'x')); | ||
| EXPECT_CALL(*router_->retry_state_, enabled()).Times(2).WillRepeatedly(Return(true)); | ||
| router_->decodeData(buf1, false); |
There was a problem hiding this comment.
💡 The 40 kept bytes go upstream through a nice mock with no expectation, so this passes even if they're never sent. Could we expect them before the drain?
| router_->decodeData(buf1, false); | |
| EXPECT_CALL(encoder1, encodeData(BufferString(std::string(40, 'x')), false)); | |
| router_->decodeData(buf1, false); |
There was a problem hiding this comment.
This still applies under either fix.
agrawroh
left a comment
There was a problem hiding this comment.
🚫 Suggested Fixes. Holding this for per-filter buffers and draining only in that mode works for us, since filters that data has passed then park into their own buffers.
- 🚨 The drain empties the shared buffer even while it holds a frame an earlier filter paused. On a retry route with Lua calling
httpCall()inbodyChunks()ahead ofbandwidth_limit, the upstream silently misses a frame that main forwards. Could it drain only in per-filter mode, or only while the buffer length equals the sum of frames the router added? - 💡 If the drain gates on per-filter mode, could it read the mode the filter manager latched through a new callback, rather than the runtime flags? The mode is fixed per stream and needs both guards, so a mid-stream flip could otherwise drain a buffer earlier filters still park into. The router-bytes check needs no callback.
- 💡 Per-filter mode defaults on in #48660, and there a retry stream stays read-disabled without this drain once a filter parks past the limit with a watermark pause and resumes while the router's kept bytes exceed half the limit. Our HTTP/1 probe never resumed. Could the two land together, or this one first with the router-bytes check?
|
/wait |
Commit Message: router: drop the kept retry body once retries are given up on buffer overflow
Additional Description: When the request body exceeds the retry/redirect buffer limit, the router gives up on retries and internal redirects but kept the body it had already buffered until the stream ended. Nothing can read those bytes any more (the retry state is reset, redirects are blocked by the overflow flag, and replay only happens on a new attempt), yet they still count toward the stream buffer limit, which can keep downstream reads disabled until the upstream responds or a timeout fires. The router now drains the kept body when it gives up. The buffer is drained rather than destroyed, and nothing is drained when the current frame is the decoding buffer itself, because that frame still has to be forwarded upstream. Raised during the review of #48660.
Risk Level: Low
Testing: Unit tests added.
Docs Changes: N/A
Release Notes: Added.