Repository navigation
http: track observed end stream per filter position in the filter manager - #49286
Conversation
…ager Signed-off-by: wbpcode <[email protected]>
|
/retest |
|
Needs a main merge. /wait |
Signed-off-by: wbpcode <[email protected]> # Conflicts: # test/common/http/filter_manager_test.cc
…positional-end-stream # Conflicts: # test/common/http/filter_manager_test.cc
…_per_filter_buffer Signed-off-by: wbpcode <[email protected]>
Signed-off-by: wbpcode <[email protected]>
agrawroh
left a comment
There was a problem hiding this comment.
🔄 Follow-ups. Defaulting the guard off keeps the shared-buffer duplicate off the default path, so nothing here blocks once CI passes.
- ❓ With the guard on, should recreation also require the end of stream at this filter?
- 💡 Could this carry the TODO to flip it that false guards here take, and could the note say the guard is incomplete until per-filter buffering lands?
- 💡 Every stream now looks up the old inject guard, which main read only when a filter injected.
- 💡 No response-side test resumes a filter before an earlier one injects, and the two-filter ext_proc cases never run with the guard on.
- 💡 The fixture gives only the first filter's config its 5 s message timeout, so the other two side streams here wait across several round trips at the 200 ms default, which the fixture says sanitizer runs can exceed.
- 💡 With the guard on, on a CONNECT tunnel with half close, a complete response after the client's end of stream now closes the stream and drops request data a filter is still injecting.
- 💡 Every current read of the marker also requires no trailers, so the trailers case this comment gives changes nothing today.
- 💡 The description still names the old guard and says the old flag is right while one injecting filter sits upstream of the resuming one, while the guard-off test shows it ending the stream with one injector that hasn't injected yet. Since it becomes the commit message, could it name the new guard, its default and that order?
| // there was no body from the HCM's point of view. This deliberately checks the stream-level | ||
| // flag rather than this filter's positional marker: recreation requires the whole request to | ||
| // have been received, wherever it is currently buffered. | ||
| if (!parent_.decoderObservedEndStream()) { |
There was a problem hiding this comment.
❓ With the guard on, should recreation also require the end of stream at this filter? This flag no longer drops while an earlier filter is still injecting, and custom_response and dynamic modules gate recreation only on it, so the new stream, which replays only the stream buffer, would lose the bytes that filter still holds.
There was a problem hiding this comment.
The whole injection APIs are tricky. Before the #43175, the injection won't update the stream level end-of-stream flag, the custom_response, dynamic module or any other filter who will recreate the stream, may lost the bytes silently.
After the #43175, the injection will overwrite the stream level end-of-stream flag, it luckily also fixed this scenario. Similar to the half-close-abortion case.
But the #43175 also introduced a side effect, it will pollute the stream level end-of-stream flag.
At the latest commit, we added another new decoder_injection_pending_ to record the pending injection, to revert the main's behaviour first.
There was a problem hiding this comment.
This now holds when the client's end arrives first, and the new comment on the pending-injection TODO covers the order where it arrives after the last injection.
| // reached the resuming filter, instead of from the stream-level flag. When enabled, | ||
| // envoy.reloadable_features.ext_proc_inject_data_with_state_update is ignored. Per-filter body | ||
| // buffering will be added behind this flag before it is enabled by default. | ||
| FALSE_RUNTIME_GUARD(envoy_reloadable_features_filter_manager_per_filter_buffer); |
There was a problem hiding this comment.
💡 Could this carry the TODO to flip it that false guards here take, and could the note say the guard is incomplete until per-filter buffering lands? Enabling it alone still hands a retrying router the body twice in the stop-all order.
There was a problem hiding this comment.
I could add a TODO but no Enabling it alone still hands a retrying router the body twice in the stop-all order because as I explained in the per-filter-buffer PR, that scenario is broken anyway, no matcher the flag's value.
There was a problem hiding this comment.
The TODO and the incomplete note are in, thanks.
| proxy_100_continue_(proxy_100_continue), | ||
| per_filter_buffer_(Runtime::runtimeFeatureEnabled( | ||
| "envoy.reloadable_features.filter_manager_per_filter_buffer")), | ||
| inject_data_with_state_update_(Runtime::runtimeFeatureEnabled( |
There was a problem hiding this comment.
💡 Every stream now looks up the old inject guard, which main read only when a filter injected. Could we read it at the two inject sites again, after the new guard check?
There was a problem hiding this comment.
We will create the filter manager for every request, and it's more robust to keep the flag's value be same in the same request. Or we may find the first injection call set the stream level end_stream flag to false, then the runtime flag is flipped to false at runtime, and the stream level end_stream flag never be set to true finally. The previous code is fragile.
There was a problem hiding this comment.
Agreed, latching it per stream keeps one stream's handling consistent if the flag flips.
| std::vector<bool> sent_headers_; | ||
| }; | ||
|
|
||
| TEST_F(FilterManagerObservedEndStreamTest, ResumedFilterDoesNotEndStreamBeforeInjectedBody) { |
There was a problem hiding this comment.
💡 No response-side test resumes a filter before an earlier one injects, and the two-filter ext_proc cases never run with the guard on. Could we add an encoder twin of this case and run one two-filter case with the guard on?
There was a problem hiding this comment.
Both cases are in, and the encoder one fails with the guard off.
| grpc_upstream_count_ = 3; | ||
| config_helper_.addConfigModifier([this](envoy::config::bootstrap::v3::Bootstrap&) { | ||
| // Filter-2: only processes the request headers. | ||
| proto_config_2_.mutable_processing_mode()->Clear(); |
There was a problem hiding this comment.
💡 The fixture gives only the first filter's config its 5 s message timeout, so the other two side streams here wait across several round trips at the 200 ms default, which the fixture says sanitizer runs can exceed. Could both get the same timeout?
There was a problem hiding this comment.
The helper's default now covers every added filter, thanks.
| Fixed a bug where a filter resuming iteration could end the stream early, dropping the remaining | ||
| body, when another filter earlier in the chain was still holding data that it later injected (for | ||
| example, three ext_proc filters processing the body in ``STREAMED`` mode). The filter manager can | ||
| now track whether the end of the stream has reached each filter. This is disabled by default and |
There was a problem hiding this comment.
💡 With the guard on, on a CONNECT tunnel with half close, a complete response after the client's end of stream now closes the stream and drops request data a filter is still injecting. Could the note say so?
There was a problem hiding this comment.
Will revert the main's behaviour.
There was a problem hiding this comment.
The close now waits for the injection to end, so the note needs nothing more.
| state_.filter_added_data_in_data_callback_ = false; | ||
| const bool data_nonempty_before_callback = data.length() > 0; | ||
| (*entry)->end_stream_ = end_stream && !filter_manager_callbacks_.requestTrailers(); | ||
| // |= as the marker latches: when trailers are parked at this filter, its own buffered data |
There was a problem hiding this comment.
💡 Every current read of the marker also requires no trailers, so the trailers case this comment gives changes nothing today. Could the comment call the latch defensive, and keep the trailer-path writes in case recreation starts reading the marker?
There was a problem hiding this comment.
The comments now say so, thanks.
Signed-off-by: wbpcode <[email protected]>
agrawroh
left a comment
There was a problem hiding this comment.
🔄 Follow-ups. The guard stays off by default, so nothing here blocks.
- 💡 With the guard on, nothing clears this when the client's last data or trailers arrive after the last injection, so recreation stays refused where main allows it and internal redirects aren't followed.
- 💡 The guard's comment now says it is incomplete until per-filter buffering lands, while this note tells operators how to enable it as the fix.
- 💡 This turns the inject guard off too, so no test pins the default path, where recreation is refused while a filter is still injecting.
- 💡 Could
dumpState()print this, since with the guard on it decides close and recreation while the stream flag it already dumps reads as ended? - 💡 The description still names the old guard and says injection no longer touches the stream-level flags, which holds only with the guard on. Since it becomes the commit message, could it name the new guard, its default and the pending-injection check?
| * without it, and the request ends with the trailers passing the filter instead (e.g. | ||
| * ext_proc in STREAMED mode forwards held trailers once the last chunk is injected). This | ||
| * stays true for the rest of the stream. | ||
| * TODO(wbpcode): handle these cases. They are not introduced by |
There was a problem hiding this comment.
💡 With the guard on, nothing clears this when the client's last data or trailers arrive after the last injection, so recreation stays refused where main allows it and internal redirects aren't followed. Could maybeEndDecode() clear it once the terminal filter decodes the end of stream, with a guard-on test and these cases updated?
| body, when another filter earlier in the chain was still holding data that it later injected (for | ||
| example, three ext_proc filters processing the body in ``STREAMED`` mode). The filter manager can | ||
| now track whether the end of the stream has reached each filter. This is disabled by default and | ||
| can be enabled by setting the runtime guard |
There was a problem hiding this comment.
💡 The guard's comment now says it is incomplete until per-filter buffering lands, while this note tells operators how to enable it as the fix. Could the note say it is incomplete too?
|
|
||
| TEST_F(FilterManagerObservedEndStreamTest, InjectionWithoutGuardLeavesRecreateToStreamFlag) { | ||
| scoped_runtime_.mergeValues( | ||
| {{"envoy.reloadable_features.ext_proc_inject_data_with_state_update", "false"}}); |
There was a problem hiding this comment.
💡 This turns the inject guard off too, so no test pins the default path, where recreation is refused while a filter is still injecting. Could a case keep that guard at its default and expect the refusal?
| bool observed_decode_end_stream_{}; | ||
| // Set to the inverse of end_stream by the last request data injection. Only maintained with | ||
| // per-filter buffer, where injection leaves observed_decode_end_stream_ untouched. | ||
| bool decoder_injection_pending_{}; |
There was a problem hiding this comment.
💡 Could dumpState() print this, since with the guard on it decides close and recreation while the stream flag it already dumps reads as ended?
Signed-off-by: wbpcode <[email protected]>
|
merge first. The flag is off by default anyway. |
…age timeout envoyproxy#48964 gave the ext_proc integration fixture a 5s default message timeout, as the filter default of 200ms is shorter than a round trip through the fake ext_proc server can take under the sanitizers. The default is set in `initializeConfig()`, which the tests with two ext_proc filters do not go through for their filter configs: they pass each one to `addDownstreamExtProcFilter()`, so both filters kept the 200ms default. Apply the same default there. This is the fixture change that landed on main as part of envoyproxy#49286, without the rest of that change. Signed-off-by: Ryan Northey <[email protected]>
…age timeout envoyproxy#48964 gave the ext_proc integration fixture a 5s default message timeout, as the filter default of 200ms is shorter than a round trip through the fake ext_proc server can take under the sanitizers. The default is set in `initializeConfig()`, which the tests with two ext_proc filters do not go through for their filter configs: they pass each one to `addDownstreamExtProcFilter()`, so both filters kept the 200ms default. Apply the same default there. This is the fixture change that landed on main as part of envoyproxy#49286, without the rest of that change. Signed-off-by: Ryan Northey <[email protected]>
…age timeout envoyproxy#48964 gave the ext_proc integration fixture a 5s default message timeout, as the filter default of 200ms is shorter than a round trip through the fake ext_proc server can take under the sanitizers. The default is set in `initializeConfig()`, which the tests with two ext_proc filters do not go through for their filter configs: they pass each one to `addDownstreamExtProcFilter()`, so both filters kept the 200ms default. Apply the same default there. This is the fixture change that landed on main as part of envoyproxy#49286, without the rest of that change. Signed-off-by: Ryan Northey <[email protected]>
…age timeout envoyproxy#48964 gave the ext_proc integration fixture a 5s default message timeout, as the filter default of 200ms is shorter than a round trip through the fake ext_proc server can take under the sanitizers. The default is set in `initializeConfig()`, which the tests with two ext_proc filters do not go through for their filter configs: they pass each one to `addDownstreamExtProcFilter()`, so both filters kept the 200ms default. Apply the same default there. This is the fixture change that landed on main as part of envoyproxy#49286, without the rest of that change. Signed-off-by: Ryan Northey <[email protected]>
…age timeout envoyproxy#48964 gave the ext_proc integration fixture a 5s default message timeout, as the filter default of 200ms is shorter than a round trip through the fake ext_proc server can take under the sanitizers. The default is set in `initializeConfig()`, which the tests with two ext_proc filters do not go through for their filter configs: they pass each one to `addDownstreamExtProcFilter()`, so both filters kept the 200ms default. Apply the same default there. This is the fixture change that landed on main as part of envoyproxy#49286, without the rest of that change. Signed-off-by: Ryan Northey <[email protected]>
…age timeout envoyproxy#48964 gave the ext_proc integration fixture a 5s default message timeout, as the filter default of 200ms is shorter than a round trip through the fake ext_proc server can take under the sanitizers. The default is set in `initializeConfig()`, which the tests with two ext_proc filters do not go through for their filter configs: they pass each one to `addDownstreamExtProcFilter()`, so both filters kept the 200ms default. Apply the same default there. This is the fixture change that landed on main as part of envoyproxy#49286, without the rest of that change. Signed-off-by: Ryan Northey <[email protected]>
…age timeout envoyproxy#48964 gave the ext_proc integration fixture a 5s default message timeout, as the filter default of 200ms is shorter than a round trip through the fake ext_proc server can take under the sanitizers. The default is set in `initializeConfig()`, which the tests with two ext_proc filters do not go through for their filter configs: they pass each one to `addDownstreamExtProcFilter()`, so both filters kept the 200ms default. Apply the same default there. This is the fixture change that landed on main as part of envoyproxy#49286, without the rest of that change. Signed-off-by: Ryan Northey <[email protected]>
…age timeout envoyproxy#48964 gave the ext_proc integration fixture a 5s default message timeout, as the filter default of 200ms is shorter than a round trip through the fake ext_proc server can take under the sanitizers. The default is set in `initializeConfig()`, which the tests with two ext_proc filters do not go through for their filter configs: they pass each one to `addDownstreamExtProcFilter()`, so both filters kept the 200ms default. Apply the same default there. This is the fixture change that landed on main as part of envoyproxy#49286, without the rest of that change. Signed-off-by: Ryan Northey <[email protected]>
…age timeout #48964 gave the ext_proc integration fixture a 5s default message timeout, as the filter default of 200ms is shorter than a round trip through the fake ext_proc server can take under the sanitizers. The default is set in `initializeConfig()`, which the tests with two ext_proc filters do not go through for their filter configs: they pass each one to `addDownstreamExtProcFilter()`, so both filters kept the 200ms default. Apply the same default there. This is the fixture change that landed on main as part of #49286, without the rest of that change. Signed-off-by: Ryan Northey <[email protected]>
…age timeout #48964 gave the ext_proc integration fixture a 5s default message timeout, as the filter default of 200ms is shorter than a round trip through the fake ext_proc server can take under the sanitizers. The default is set in `initializeConfig()`, which the tests with two ext_proc filters do not go through for their filter configs: they pass each one to `addDownstreamExtProcFilter()`, so both filters kept the 200ms default. Apply the same default there. This is the fixture change that landed on main as part of #49286, without the rest of that change. Signed-off-by: Ryan Northey <[email protected]>
…age timeout #48964 gave the ext_proc integration fixture a 5s default message timeout, as the filter default of 200ms is shorter than a round trip through the fake ext_proc server can take under the sanitizers. The default is set in `initializeConfig()`, which the tests with two ext_proc filters do not go through for their filter configs: they pass each one to `addDownstreamExtProcFilter()`, so both filters kept the 200ms default. Apply the same default there. This is the fixture change that landed on main as part of #49286, without the rest of that change. Signed-off-by: Ryan Northey <[email protected]>
…age timeout #48964 gave the ext_proc integration fixture a 5s default message timeout, as the filter default of 200ms is shorter than a round trip through the fake ext_proc server can take under the sanitizers. The default is set in `initializeConfig()`, which the tests with two ext_proc filters do not go through for their filter configs: they pass each one to `addDownstreamExtProcFilter()`, so both filters kept the 200ms default. Apply the same default there. This is the fixture change that landed on main as part of #49286, without the rest of that change. Signed-off-by: Ryan Northey <[email protected]>
Commit Message: http: track observed end stream per filter position in the filter manager
Additional Description:
Split out of #48660.
The end_stream computed when a stopped filter resumes (
commonContinue()) previously read the stream-levelobserved_[de|en]code_end_stream_flag, which records that the codec has seen the end of the stream. For filters that hold data and re-inject it (ext_proc style), that flag is positionally wrong: the end of the stream may not have reached the resuming filter yet. #43175 fixed the two-filter instance of this (#41654) by lettinginject[De|En]codedDataToFilterChain()rewrite the stream-level flag under the runtime guard. That mechanism is last-writer-wins on a single shared flag, which is only correct while there is one injecting filter upstream of any resuming filter: with three or more stopping/injecting filters, an upstream filter's finalinject(end_stream=true)can land between a mid-chain filter's injections and a downstream filter's resume, making the downstream filter release buffered data with a prematureend_stream=true(truncating the remaining body).Here is the A → B → C timeline:
end_stream=true(a1, false)(b1, false)(a2, true)continueDecoding()and thendoData(observedEndStream() && ...)This PR replaces the mechanism with a per-filter
observed_end_stream_marker: frame deliveries and parked frames latch it at the position they actually reached, and the inject APIs author it at the injecting filter's own position only. Resumption reads the resuming filter's own marker, so the computation is correct for any number of stopping/injecting filters. The stream-level flags are no longer modified by data injection.Risk Level: Medium
Testing: unit tests (filter_manager_test), ext_proc integration test
Docs Changes: N/A
Release Notes: added
Runtime guard: envoy.reloadable_features.filter_manager_per_filter_observed_end_stream