Repository navigation
http: forward added trailers once from the filter holding them - #49241
Conversation
Signed-off-by: wbpcode <[email protected]>
|
/retest |
2 similar comments
|
/retest |
|
/retest |
… dev-filter-manager-held-trailers
Signed-off-by: wbpcode <[email protected]>
agrawroh
left a comment
There was a problem hiding this comment.
🚫 Suggested Fixes. One holder per direction is the right shape, and the new tests pin most of it, so only the new guard-off test blocks.
⚠️ The new guard-off request test trips thedecoder_filter_chain_complete_assert in every build with assertions on, so asan, msan, tsan and two compile-time-option jobs abortfilter_manager_testbefore its 116 invariant cases run.- 💡 The release note covers only added trailers, but the guard also changes codec trailers a filter holds, and "never forwarded past" is off since the codec did get added trailers once a later stopped filter resumed.
- 💡 Each
TrailersStatepads a pointer and a bool to 16 bytes, so every filter manager grows 32 bytes. - 💡 The new integration case runs on the HTTP/2 only
FilterIntegrationTest, so it never runs on HTTP/1 and itsHTTP1check is always true. - 💡 The "never sent" comment is off, since at main the codec gets these trailers once from filter 1's resume and only filter 1 misses them.
- 💡 No guard-off test runs the legacy response dispatch at the end of
encodeData(), since the only response guard-off case adds its trailers in a pass that stops early and resumes with them already present. - 💡 The invariant suite stays green with the new
encodeData()stop-path forward deleted, sinceresume()restarts the stopper and its own resume sends the trailers. - 💡
concat(),bufferRequestBodyAtTwoFilters()andbufferResponseBodyAtTwoFilters()have no callers.
| filter_manager_->decodeHeaders(*request_headers_, false); | ||
| decodeData("aaa", true); | ||
|
|
||
| EXPECT_EQ((Chunks{{"aaa", false}}), records_[1].decoded_data); | ||
| // Sent once by the resumed filter 0 and again from filter 0 after the data loop. | ||
| EXPECT_EQ(2, records_[1].decoded_trailers); | ||
| EXPECT_EQ(2, records_[2].decoded_trailers); |
There was a problem hiding this comment.
decoder_filter_chain_complete_ assert in every build with assertions on, so asan, msan, tsan and two compile-time-option jobs abort filter_manager_test before its 116 invariant cases run. Could filter 1 stop on the trailers, so the first dispatch never completes the chain and the double delivery still shows?
| filter_manager_->decodeHeaders(*request_headers_, false); | |
| decodeData("aaa", true); | |
| EXPECT_EQ((Chunks{{"aaa", false}}), records_[1].decoded_data); | |
| // Sent once by the resumed filter 0 and again from filter 0 after the data loop. | |
| EXPECT_EQ(2, records_[1].decoded_trailers); | |
| EXPECT_EQ(2, records_[2].decoded_trailers); | |
| // Filter 1 holds the trailers, so the first dispatch does not complete the chain and the second | |
| // one does not trip the decoder-complete assertion in debug builds. | |
| records_[1].decode_trailers = [] { return FilterTrailersStatus::StopIteration; }; | |
| filter_manager_->decodeHeaders(*request_headers_, false); | |
| decodeData("aaa", true); | |
| EXPECT_EQ((Chunks{{"aaa", false}}), records_[1].decoded_data); | |
| // Sent once by the resumed filter 0 and again from filter 0 after the data loop. | |
| EXPECT_EQ(2, records_[1].decoded_trailers); | |
| EXPECT_EQ(0, records_[2].decoded_trailers); |
| @@ -0,0 +1,7 @@ | |||
| Fixed filter manager handling of trailers added by a filter (``addDecodedTrailers()`` / | |||
There was a problem hiding this comment.
💡 The release note covers only added trailers, but the guard also changes codec trailers a filter holds, and "never forwarded past" is off since the codec did get added trailers once a later stopped filter resumed. Could the note, commit message and guard comment say all trailers now move once from their holder, skipping no filter?
| // are parked before filter_, which stopped all iteration, and continue from it. | ||
| bool processed_{}; | ||
| }; | ||
| TrailersState<ActiveStreamDecoderFilter> request_trailers_state_; |
There was a problem hiding this comment.
💡 Each TrailersState pads a pointer and a bool to 16 bytes, so every filter manager grows 32 bytes. Could the flags sit beside forward_held_trailers_? That printed 1176 bytes, not 1192, with the filter manager and HCM tests green, and processed_ matched the holder's end_stream_ across those and the integration tests, so it may need no field.
There was a problem hiding this comment.
rather than the 32 bytes, I inclined to keep the code clean and easy to read.
| } | ||
| } | ||
|
|
||
| TEST_P(FilterIntegrationTest, AddedResponseTrailersReachLaterBufferingFilter) { |
There was a problem hiding this comment.
💡 The new integration case runs on the HTTP/2 only FilterIntegrationTest, so it never runs on HTTP/1 and its HTTP1 check is always true. The same body passes all 46 cases on the multi-protocol suite, and with the guard off its HTTP/1 cases hang too.
| TEST_P(FilterIntegrationTest, AddedResponseTrailersReachLaterBufferingFilter) { | |
| TEST_P(MultiProtocolFilterIntegrationTest, AddedResponseTrailersReachLaterBufferingFilter) { |
| encodeHeaders(false); | ||
| encodeData("aaa", true); | ||
|
|
||
| // Previously the trailers were never sent. |
There was a problem hiding this comment.
💡 The "never sent" comment is off, since at main the codec gets these trailers once from filter 1's resume and only filter 1 misses them.
| // Previously the trailers were never sent. | |
| // Without the guard, filter 1 never receives these trailers. |
| if (forward_held_trailers_) { | ||
| // Trailers added in this pass follow the data from the filter holding them, if it iterates. | ||
| forwardResponseTrailers(); | ||
| } else if (trailers_added_entry != encoder_filters_.end()) { |
There was a problem hiding this comment.
💡 No guard-off test runs the legacy response dispatch at the end of encodeData(), since the only response guard-off case adds its trailers in a pass that stops early and resumes with them already present. Emptying this branch still passed the filter manager and HCM suites. Could a guard-off case with no stopping filter cover it?
| if (c.stop_kind != TrailersStopKind::None && c.stop_kind != TrailersStopKind::ContinueOnData) { | ||
| resume(filterAt(c.stopper)); | ||
| } |
There was a problem hiding this comment.
💡 The invariant suite stays green with the new encodeData() stop-path forward deleted, since resume() restarts the stopper and its own resume sends the trailers. Could a buffering stopper be left to resume on its own? With this change that mutant fails three response cases.
| if (c.stop_kind != TrailersStopKind::None && c.stop_kind != TrailersStopKind::ContinueOnData) { | |
| resume(filterAt(c.stopper)); | |
| } | |
| if (c.stop_kind == TrailersStopKind::BufferData) { | |
| // A filter that buffers until the end of the stream resumes only once the trailers reach it. | |
| const size_t i = filterAt(c.stopper); | |
| EXPECT_TRUE(request() | |
| ? dynamic_cast<ActiveStreamDecoderFilter*>(filters_[i]->decoder_callbacks_) | |
| ->canIterate() | |
| : dynamic_cast<ActiveStreamEncoderFilter*>(filters_[i]->encoder_callbacks_) | |
| ->canIterate()); | |
| } else if (c.stop_kind != TrailersStopKind::None && | |
| c.stop_kind != TrailersStopKind::ContinueOnData) { | |
| resume(filterAt(c.stopper)); | |
| } |
| TestResponseTrailerMapImpl{{"trailer", "value"}})); | ||
| } | ||
|
|
||
| static std::string concat(const Chunks& chunks) { |
There was a problem hiding this comment.
💡 concat(), bufferRequestBodyAtTwoFilters() and bufferResponseBodyAtTwoFilters() have no callers. Could we drop them?
Signed-off-by: wbpcode <[email protected]>
|
/retest |
2 similar comments
|
/retest |
|
/retest |
…ilers (#49151) **Commit Message:** http: fix body drop when StopAllIteration filter re-buffers until trailers **Additional Description:** #49241 landed the held-trailers forwarding fix while this PR was in review, so merging `main` narrows this PR to the remaining nested-continuation bug plus the extra unit/integration tests and `addEncodedTrailers()` doc note. When a filter paused in `decodeHeaders(false)` or `encodeHeaders(false)` with `StopAllIterationAndBuffer` / `StopAllIterationAndWatermark` resumes (`commonContinue()`), `iterate_from_current_filter_` stays `true` for the whole outer `commonContinue()` call. If that filter then re-buffers the body in `decodeData(false)` / `encodeData(false)` (`StopIterationAndBuffer`) and returns `Continue` from `decodeTrailers()` / `encodeTrailers()`, `commonHandleAfterTrailersCallback()` runs a nested `commonContinue()` *after* `end_stream_` has been marked `true` on the filter; because `iterate_from_current_filter_` is still `true`, the nested `doData(false)` starts at the current filter, hits `if ((*entry)->end_stream_) return;`, and drops the buffered body before forwarding the trailers. Clearing `iterate_from_current_filter_` in `commonHandleAfterTrailersCallback()` (under `envoy.reloadable_features.filter_manager_forward_held_trailers`) starts the nested pass at the next filter as intended. **Risk Level:** Low (runtime guarded behind `envoy.reloadable_features.filter_manager_forward_held_trailers`) **Testing:** Unit tests in `test/common/http/filter_manager_test.cc` and integration tests in `test/integration/filter_integration_test.cc` **Docs Changes:** `addEncodedTrailers()` doc comment in `envoy/http/filter.h` **Release Notes:** Added **Runtime guard:** `envoy.reloadable_features.filter_manager_forward_held_trailers` **AI Usage:** Generated by Gemini; reviewed, improved by paul-r-gall. --------- Signed-off-by: Paul Ogilby <[email protected]>
Commit Message: http: forward added trailers once from the filter holding them
Fixes the filter manager's handling of trailers added by a filter (
addDecodedTrailers()/addEncodedTrailers()):the end of the stream),
encodeData()returned before dispatching the added trailers, so thatfilter and every filter after it never saw them and the response could be held forever.
commonContinue()dispatched the added trailers, and
decodeData()dispatched them again from the adder after theloop, so later filters (including the router) decoded the trailers twice.
The filter manager now records the single filter holding the trailers of each direction: the
filter that added them, then each filter they reach, until they leave the chain. Trailers are
forwarded once from the holder, and only while it iterates (at the end of a data pass, when a
filter stopping on the data ends the pass, and when the holder resumes). Trailers parked at a
filter that stopped all iteration are delivered to that filter once it resumes.
Additional Description: Split out of #48660, where the same issues were found; the fix does not
depend on per-filter buffers.
Risk Level: Medium
Testing: Unit tests + integration
Docs Changes: N/A
Release Notes: Added.
Runtime guard:
envoy.reloadable_features.filter_manager_forward_held_trailers