Skip to content

Support two ext_proc filters in the chain 2nd attempt - #43175

Merged
yanavlasov merged 15 commits into
envoyproxy:mainfrom
yanjunxiang-google:new_api
Feb 13, 2026
Merged

yanavlasov merged 15 commits into
envoyproxy:mainfrom
yanjunxiang-google:new_api

Conversation

@yanjunxiang-google

@yanjunxiang-google yanjunxiang-google commented Jan 27, 2026 •

Copy link
Copy Markdown
Contributor

This is the 2nd attempt to fix #41654.

The 1st attempt is #43042

The root cause of the issue is when the 2nd filter resume the processing:

envoy/source/common/http/filter_manager.cc

Line 132 in e45201c

doData(observedEndStream() && !had_trailers_before_data);
, it is using an outdated observedEndStream() flag as end_of_stream. This flag is set to true once Envoy sees data with end_of_stream set to true either from downstream client or backend server. However, In the ext_proc case, after the data with end_of_stream=true is received by Envoy, it is sent out to the side-stream server and re-injected back to Envoy, the observedEndStream() flag has to be updated during re-injection. Otherwise, the 2nd filter commonContinue() deem the full body is in buffer, i.e, end_of_stream=true, even the 1st filter is still injecting more data.

The issue is reproduced in both ext_proc STREAMED and FULL_DUPLEX_STREAMED modes, also in both request and response directions. Please check the added integration tests.

@repokitteh-read-only

Copy link
Copy Markdown

As a reminder, PRs marked as draft will not be automatically assigned reviewers,
or be handled by maintainer-oncall triage.

Please mark your PR as ready when you want it to be reviewed!

🐱

Caused by: #43175 was opened by yanjunxiang-google.

see: more, trace.

@yanjunxiang-google

Copy link
Copy Markdown
Contributor Author

/assign @tyxia @yanavlasov @wbpcode

@yanjunxiang-google

Copy link
Copy Markdown
Contributor Author

/retest

@yanjunxiang-google

Copy link
Copy Markdown
Contributor Author

/assign @stevenzzzz

…end_stream=true into filter chain

Signed-off-by: Yanjun Xiang <[email protected]>
@yanjunxiang-google

Copy link
Copy Markdown
Contributor Author

/retest

Signed-off-by: Yanjun Xiang <[email protected]>
Signed-off-by: Yanjun Xiang <[email protected]>
Signed-off-by: Yanjun Xiang <[email protected]>
@repokitteh-read-only

Copy link
Copy Markdown

CC @envoyproxy/runtime-guard-changes: FYI only for changes made to (source/common/runtime/runtime_features.cc).

🐱

Caused by: #43175 was synchronize by yanjunxiang-google.

see: more, trace.

Signed-off-by: Yanjun Xiang <[email protected]>
Signed-off-by: Yanjun Xiang <[email protected]>

@stevenzzzz stevenzzzz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not just ext_proc filter, any filter doing data injections following the same pattern would trigger it, right?

Comment thread envoy/http/filter.h Resolved
@yanjunxiang-google

Copy link
Copy Markdown
Contributor Author

/retest

@wbpcode

wbpcode commented Feb 2, 2026

Copy link
Copy Markdown
Member

Rather than adding a new hack interface here, is that possible to resue the ActiveStreamFilterBase::end_stream_{}; to determine whether a filter saw the end_stream flag?

@wbpcode

wbpcode commented Feb 2, 2026

Copy link
Copy Markdown
Member

/wait-any

@yanjunxiang-google

yanjunxiang-google commented Feb 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Rather than adding a new hack interface here, is that possible to resue the ActiveStreamFilterBase::end_stream_{}; to determine whether a filter saw the end_stream flag?

@wbpcode could you please elaborate your ideas? I tried below, it does not work:

diff --git a/source/common/http/filter_manager.cc b/source/common/http/filter_manager.cc
index fbf9a72c3e..a1f2fc1a14 100644
--- a/source/common/http/filter_manager.cc
+++ b/source/common/http/filter_manager.cc
@@ -129,7 +129,7 @@ void ActiveStreamFilterBase::commonContinue() {
   // on doData() to do so.
   const bool had_trailers_before_data = hasTrailers();
   if (bufferedData()) {
-    doData(observedEndStream() && !had_trailers_before_data);
+    doData(end_stream_ && !had_trailers_before_data);
   }

The reason this does not work is because end_stream_ is calculated based on observedEndStream() during the doData() call.

Adding a if (end_stream_) check before state update in injectDecodedDataToFilterChain() also does not work as it still breaks file_system_buffer integration test.

@yanjunxiang-google

Copy link
Copy Markdown
Contributor Author

/retest

@yanjunxiang-google

Copy link
Copy Markdown
Contributor Author

@wbpcode you can check: #43399. Or just run "bazel test test/integration:all" with that one line change.

@yanjunxiang-google

Copy link
Copy Markdown
Contributor Author

/retest

@yanjunxiang-google

Copy link
Copy Markdown
Contributor Author

Kind Ping!

@yanavlasov
yanavlasov merged commit 867251a into envoyproxy:main Feb 13, 2026
27 checks passed
botengyao pushed a commit to botengyao/envoy that referenced this pull request Feb 19, 2026
This is the 2nd attempt to fix
envoyproxy#41654.

The 1st attempt is envoyproxy#43042


The root cause of the issue is when the 2nd filter resume the
processing:


[envoy/source/common/http/filter_manager.cc](https://github.com/envoyproxy/envoy/blob/e45201c87d8481ecd72299139102d9ebf049cf75/source/common/http/filter_manager.cc#L132)

Line 132 in
[e45201c](envoyproxy@e45201c)

 doData(observedEndStream() && !had_trailers_before_data); 
, it is using an outdated observedEndStream() flag as end_of_stream.
This flag is set to true once Envoy sees data with end_of_stream set to
true either from downstream client or backend server. However, In the
ext_proc case, after the data with end_of_stream=true is received by
Envoy, it is sent out to the side-stream server and re-injected back to
Envoy, the observedEndStream() flag has to be updated during
re-injection. Otherwise, the 2nd filter commonContinue() deem the full
body is in buffer, i.e, end_of_stream=true, even the 1st filter is still
injecting more data.

The issue is reproduced in both ext_proc STREAMED and
FULL_DUPLEX_STREAMED modes, also in both request and response
directions. Please check the added integration tests.

---------

Signed-off-by: Yanjun Xiang <[email protected]>
Signed-off-by: Boteng Yao <[email protected]>
botengyao pushed a commit to botengyao/envoy that referenced this pull request Feb 20, 2026
This is the 2nd attempt to fix
envoyproxy#41654.

The 1st attempt is envoyproxy#43042


The root cause of the issue is when the 2nd filter resume the
processing:


[envoy/source/common/http/filter_manager.cc](https://github.com/envoyproxy/envoy/blob/e45201c87d8481ecd72299139102d9ebf049cf75/source/common/http/filter_manager.cc#L132)

Line 132 in
[e45201c](envoyproxy@e45201c)

 doData(observedEndStream() && !had_trailers_before_data); 
, it is using an outdated observedEndStream() flag as end_of_stream.
This flag is set to true once Envoy sees data with end_of_stream set to
true either from downstream client or backend server. However, In the
ext_proc case, after the data with end_of_stream=true is received by
Envoy, it is sent out to the side-stream server and re-injected back to
Envoy, the observedEndStream() flag has to be updated during
re-injection. Otherwise, the 2nd filter commonContinue() deem the full
body is in buffer, i.e, end_of_stream=true, even the 1st filter is still
injecting more data.

The issue is reproduced in both ext_proc STREAMED and
FULL_DUPLEX_STREAMED modes, also in both request and response
directions. Please check the added integration tests.

---------

Signed-off-by: Yanjun Xiang <[email protected]>
Signed-off-by: Boteng Yao <[email protected]>
phlax pushed a commit that referenced this pull request Feb 23, 2026
This is the 2nd attempt to fix
#41654.

The 1st attempt is #43042


The root cause of the issue is when the 2nd filter resume the
processing:


[envoy/source/common/http/filter_manager.cc](https://github.com/envoyproxy/envoy/blob/e45201c87d8481ecd72299139102d9ebf049cf75/source/common/http/filter_manager.cc#L132)

Line 132 in
[e45201c](e45201c)

 doData(observedEndStream() && !had_trailers_before_data); 
, it is using an outdated observedEndStream() flag as end_of_stream.
This flag is set to true once Envoy sees data with end_of_stream set to
true either from downstream client or backend server. However, In the
ext_proc case, after the data with end_of_stream=true is received by
Envoy, it is sent out to the side-stream server and re-injected back to
Envoy, the observedEndStream() flag has to be updated during
re-injection. Otherwise, the 2nd filter commonContinue() deem the full
body is in buffer, i.e, end_of_stream=true, even the 1st filter is still
injecting more data.

The issue is reproduced in both ext_proc STREAMED and
FULL_DUPLEX_STREAMED modes, also in both request and response
directions. Please check the added integration tests.

---------

Signed-off-by: Yanjun Xiang <[email protected]>
Signed-off-by: Boteng Yao <[email protected]>
nerdalert added a commit to nerdalert/envoy-ext-proc-bug-repro that referenced this pull request Mar 16, 2026
Reproducer and validation for the EoS interleaving bug when two ext_proc
filters are chained in Envoy. Tracks the BBR + EPP issue reported in
gateway-api-inference-extension#2115.

Stage 1: Bug reproduced on Istio 1.28.1 (Envoy 1.36.3-dev) - 24/100
requests truncated with body-delay=20ms on body-processing ext_proc.

Stage 2: Fix (envoyproxy/envoy#43175) confirmed present in Istio 1.29.1
(Envoy 1.37.1-dev) via source code verification of runtime feature
envoy_reloadable_features_ext_proc_inject_data_with_state_update.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
nickshokri pushed a commit to nickshokri/envoy that referenced this pull request Mar 17, 2026
This is the 2nd attempt to fix
envoyproxy#41654.

The 1st attempt is envoyproxy#43042

The root cause of the issue is when the 2nd filter resume the
processing:

[envoy/source/common/http/filter_manager.cc](https://github.com/envoyproxy/envoy/blob/e45201c87d8481ecd72299139102d9ebf049cf75/source/common/http/filter_manager.cc#L132)

Line 132 in
[e45201c](envoyproxy@e45201c)

 doData(observedEndStream() && !had_trailers_before_data);
, it is using an outdated observedEndStream() flag as end_of_stream.
This flag is set to true once Envoy sees data with end_of_stream set to
true either from downstream client or backend server. However, In the
ext_proc case, after the data with end_of_stream=true is received by
Envoy, it is sent out to the side-stream server and re-injected back to
Envoy, the observedEndStream() flag has to be updated during
re-injection. Otherwise, the 2nd filter commonContinue() deem the full
body is in buffer, i.e, end_of_stream=true, even the 1st filter is still
injecting more data.

The issue is reproduced in both ext_proc STREAMED and
FULL_DUPLEX_STREAMED modes, also in both request and response
directions. Please check the added integration tests.

---------

Signed-off-by: Yanjun Xiang <[email protected]>
Signed-off-by: nick <[email protected]>
nickshokri pushed a commit to nickshokri/envoy that referenced this pull request Mar 17, 2026
This is the 2nd attempt to fix
envoyproxy#41654.

The 1st attempt is envoyproxy#43042

The root cause of the issue is when the 2nd filter resume the
processing:

[envoy/source/common/http/filter_manager.cc](https://github.com/envoyproxy/envoy/blob/e45201c87d8481ecd72299139102d9ebf049cf75/source/common/http/filter_manager.cc#L132)

Line 132 in
[e45201c](envoyproxy@e45201c)

 doData(observedEndStream() && !had_trailers_before_data);
, it is using an outdated observedEndStream() flag as end_of_stream.
This flag is set to true once Envoy sees data with end_of_stream set to
true either from downstream client or backend server. However, In the
ext_proc case, after the data with end_of_stream=true is received by
Envoy, it is sent out to the side-stream server and re-injected back to
Envoy, the observedEndStream() flag has to be updated during
re-injection. Otherwise, the 2nd filter commonContinue() deem the full
body is in buffer, i.e, end_of_stream=true, even the 1st filter is still
injecting more data.

The issue is reproduced in both ext_proc STREAMED and
FULL_DUPLEX_STREAMED modes, also in both request and response
directions. Please check the added integration tests.

---------

Signed-off-by: Yanjun Xiang <[email protected]>
Signed-off-by: nick <[email protected]>
fishcakez pushed a commit to fishcakez/envoy that referenced this pull request Mar 25, 2026
This is the 2nd attempt to fix
envoyproxy#41654.

The 1st attempt is envoyproxy#43042


The root cause of the issue is when the 2nd filter resume the
processing:


[envoy/source/common/http/filter_manager.cc](https://github.com/envoyproxy/envoy/blob/e45201c87d8481ecd72299139102d9ebf049cf75/source/common/http/filter_manager.cc#L132)

Line 132 in
[e45201c](envoyproxy@e45201c)

 doData(observedEndStream() && !had_trailers_before_data); 
, it is using an outdated observedEndStream() flag as end_of_stream.
This flag is set to true once Envoy sees data with end_of_stream set to
true either from downstream client or backend server. However, In the
ext_proc case, after the data with end_of_stream=true is received by
Envoy, it is sent out to the side-stream server and re-injected back to
Envoy, the observedEndStream() flag has to be updated during
re-injection. Otherwise, the 2nd filter commonContinue() deem the full
body is in buffer, i.e, end_of_stream=true, even the 1st filter is still
injecting more data.

The issue is reproduced in both ext_proc STREAMED and
FULL_DUPLEX_STREAMED modes, also in both request and response
directions. Please check the added integration tests.

---------

Signed-off-by: Yanjun Xiang <[email protected]>
krinkinmu pushed a commit to grnmeira/envoy that referenced this pull request Apr 20, 2026
This is the 2nd attempt to fix
envoyproxy#41654.

The 1st attempt is envoyproxy#43042


The root cause of the issue is when the 2nd filter resume the
processing:


[envoy/source/common/http/filter_manager.cc](https://github.com/envoyproxy/envoy/blob/e45201c87d8481ecd72299139102d9ebf049cf75/source/common/http/filter_manager.cc#L132)

Line 132 in
[e45201c](envoyproxy@e45201c)

 doData(observedEndStream() && !had_trailers_before_data); 
, it is using an outdated observedEndStream() flag as end_of_stream.
This flag is set to true once Envoy sees data with end_of_stream set to
true either from downstream client or backend server. However, In the
ext_proc case, after the data with end_of_stream=true is received by
Envoy, it is sent out to the side-stream server and re-injected back to
Envoy, the observedEndStream() flag has to be updated during
re-injection. Otherwise, the 2nd filter commonContinue() deem the full
body is in buffer, i.e, end_of_stream=true, even the 1st filter is still
injecting more data.

The issue is reproduced in both ext_proc STREAMED and
FULL_DUPLEX_STREAMED modes, also in both request and response
directions. Please check the added integration tests.

---------

Signed-off-by: Yanjun Xiang <[email protected]>
jwendell pushed a commit to jwendell/envoy that referenced this pull request Aug 25, 2026
Backport to release/v1.36 of envoyproxy#43175. This is a cherry-pick of the
release/v1.37 commit 567847a, which in
turn cherry-picked the main-branch commit
867251a.

This is the 2nd attempt to fix
envoyproxy#41654.

The 1st attempt is envoyproxy#43042

The root cause of the issue is when the 2nd filter resume the
processing, `doData(observedEndStream() && !had_trailers_before_data)`
in `source/common/http/filter_manager.cc` uses an outdated
`observedEndStream()` flag as `end_of_stream`. This flag is set to true
once Envoy sees data with end_of_stream set to true either from
downstream client or backend server. However, in the ext_proc case,
after the data with end_of_stream=true is received by Envoy, it is sent
out to the side-stream server and re-injected back to Envoy, the
`observedEndStream()` flag has to be updated during re-injection.
Otherwise, the 2nd filter `commonContinue()` deems the full body is in
buffer, i.e. end_of_stream=true, even the 1st filter is still injecting
more data.

The issue is reproduced in both ext_proc STREAMED and
FULL_DUPLEX_STREAMED modes, also in both request and response
directions. Please check the added integration tests.

Backport notes (changes needed to resolve conflicts against 1.36):

- Changelog: 1.36 uses the fragment-directory format, so the
  `changelogs/current.yaml` entry was converted to
  `changelogs/current/bug_fixes/ext_proc__support-two-ext-proc-filters.rst`.
- `source/common/runtime/runtime_features.cc`: only added the
  `envoy.reloadable_features.ext_proc_inject_data_with_state_update`
  guard; the unrelated `ext_proc_stream_close_optimization` guard does
  not exist on 1.36 and was dropped from the surrounding context.
- `ext_proc_integration_common.cc`: wrapped 1.36's existing
  `composite_test_`/`downstream_filter` config setup in the new
  `if (!two_ext_proc_filters_)` guard rather than the 1.37
  `config_option.filter_setup` enum, which does not exist on 1.36.
- `filter_test.cc`: 1.36 keeps `HttpFilterTest` in
  `filter_test_common.*`; the real change (setting the runtime guard in
  `initialize()`) applies only to `filter_test_common.cc`.
- `filter_test_common.h`/`BUILD`: added the `scoped_runtime_`
  (`TestScopedRuntime`) member, its `test_runtime.h` include and the
  `//test/test_common:test_runtime_lib` dep, none of which existed on
  1.36.
- `ext_proc_full_duplex_integration_test.cc`: kept the three new
  `TwoExtProcFilters*` tests and dropped the 1.37-only
  `ServerWaitforEnvoyHalfCloseThenCloseStream` test (not part of this
  change; depends on the 1.37-only `ext_proc_graceful_grpc_close`
  feature).
- Fuzzer: kept only the `ext_proc_inject_data_with_state_update` runtime
  override; the 1.37-only `input.response()` size guard was dropped.

Signed-off-by: Yanjun Xiang <[email protected]>
Signed-off-by: Boteng Yao <[email protected]>
Signed-off-by: Jonh Wendell <[email protected]>
jwendell pushed a commit that referenced this pull request Aug 26, 2026
Backport to release/v1.36 of #43175. This is a cherry-pick of the
release/v1.37 commit 567847a, which in
turn cherry-picked the main-branch commit
867251a.

This is the 2nd attempt to fix
#41654.

The 1st attempt is #43042

The root cause of the issue is when the 2nd filter resume the
processing, `doData(observedEndStream() && !had_trailers_before_data)`
in `source/common/http/filter_manager.cc` uses an outdated
`observedEndStream()` flag as `end_of_stream`. This flag is set to true
once Envoy sees data with end_of_stream set to true either from
downstream client or backend server. However, in the ext_proc case,
after the data with end_of_stream=true is received by Envoy, it is sent
out to the side-stream server and re-injected back to Envoy, the
`observedEndStream()` flag has to be updated during re-injection.
Otherwise, the 2nd filter `commonContinue()` deems the full body is in
buffer, i.e. end_of_stream=true, even the 1st filter is still injecting
more data.

The issue is reproduced in both ext_proc STREAMED and
FULL_DUPLEX_STREAMED modes, also in both request and response
directions. Please check the added integration tests.

Backport notes (changes needed to resolve conflicts against 1.36):

- Changelog: 1.36 uses the fragment-directory format, so the
  `changelogs/current.yaml` entry was converted to
  `changelogs/current/bug_fixes/ext_proc__support-two-ext-proc-filters.rst`.
- `source/common/runtime/runtime_features.cc`: only added the
  `envoy.reloadable_features.ext_proc_inject_data_with_state_update`
  guard; the unrelated `ext_proc_stream_close_optimization` guard does
  not exist on 1.36 and was dropped from the surrounding context.
- `ext_proc_integration_common.cc`: wrapped 1.36's existing
  `composite_test_`/`downstream_filter` config setup in the new
  `if (!two_ext_proc_filters_)` guard rather than the 1.37
  `config_option.filter_setup` enum, which does not exist on 1.36.
- `filter_test.cc`: 1.36 keeps `HttpFilterTest` in
  `filter_test_common.*`; the real change (setting the runtime guard in
  `initialize()`) applies only to `filter_test_common.cc`.
- `filter_test_common.h`/`BUILD`: added the `scoped_runtime_`
  (`TestScopedRuntime`) member, its `test_runtime.h` include and the
  `//test/test_common:test_runtime_lib` dep, none of which existed on
  1.36.
- `ext_proc_full_duplex_integration_test.cc`: kept the three new
  `TwoExtProcFilters*` tests and dropped the 1.37-only
  `ServerWaitforEnvoyHalfCloseThenCloseStream` test (not part of this
  change; depends on the 1.37-only `ext_proc_graceful_grpc_close`
  feature).
- Fuzzer: kept only the `ext_proc_inject_data_with_state_update` runtime
  override; the 1.37-only `input.response()` size guard was dropped.

Signed-off-by: Yanjun Xiang <[email protected]>
Signed-off-by: Boteng Yao <[email protected]>
Signed-off-by: Jonh Wendell <[email protected]>
wbpcode added a commit that referenced this pull request Nov 22, 2026
…ager (#49286)

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-level
`observed_[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 letting
`inject[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 final `inject(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
premature `end_stream=true` (truncating the remaining body).

Here is the A → B → C timeline:

| Step | Event | Stream-level flag | Actual state at each filter |
|---|---|---|---|
| 1 | The client's last chunk arrives with `end_stream=true` | **true**
(set by the codec) | A has the whole stream; nothing final has reached B
or C |
| 2 | A injects `(a1, false)` | **false** | B holds a1 and stops; A
still owes a2 |
| 3 | B's side stream answers a1 quickly, so B injects `(b1, false)` |
**false** | C receives b1, stops, and buffers it |
| 4 | A's side stream answers, so A injects `(a2, true)` | **true**
(written by A) | The frame stops at B, which holds a2 while it waits on
its side stream; **C never sees this frame** |
| 5 | C's async work finishes, so it calls `continueDecoding()` and then
`doData(observedEndStream() && ...)` | reads **true** | But B still owes
C the processed a2 (b2) |

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

---------

Signed-off-by: wbpcode <[email protected]>
zmiklank pushed a commit to openshift-service-mesh/envoy that referenced this pull request Nov 26, 2026
…) (envoyproxy#618) (envoyproxy#620)

Backport to release/v1.34 of envoyproxy#43175. This is a cherry-pick of the
release/v1.35 commit 05ae42b67805fd461a85bde30fad4ce7f461db32, which in
turn backported the release/v1.36 commit
ac77ca1, itself a cherry-pick of the
release/v1.37 commit 567847a, itself a
cherry-pick of the main-branch commit
867251a.

This is the 2nd attempt to fix
envoyproxy#41654.

The 1st attempt is envoyproxy#43042

The root cause of the issue is when the 2nd filter resume the
processing, `doData(observedEndStream() && !had_trailers_before_data)`
in `source/common/http/filter_manager.cc` uses an outdated
`observedEndStream()` flag as `end_of_stream`. This flag is set to true
once Envoy sees data with end_of_stream set to true either from
downstream client or backend server. However, in the ext_proc case,
after the data with end_of_stream=true is received by Envoy, it is sent
out to the side-stream server and re-injected back to Envoy, the
`observedEndStream()` flag has to be updated during re-injection.
Otherwise, the 2nd filter `commonContinue()` deems the full body is in
buffer, i.e. end_of_stream=true, even the 1st filter is still injecting
more data.

The issue is reproduced in both ext_proc STREAMED and
FULL_DUPLEX_STREAMED modes, also in both request and response
directions. Please check the added integration tests.

Backport notes (changes needed to resolve conflicts against 1.34):

- The source fix (filter_manager.cc, processor_state.cc) applied
  cleanly.
- runtime_features.cc: kept 1.34's existing ext_proc guards and inserted
  only the new
  `envoy.reloadable_features.ext_proc_inject_data_with_state_update`
  guard alphabetically; the 1.35-only `ext_proc_fail_close_spurious_resp`
  context guard does not exist on 1.34 and was dropped.
- All test changes were ported into 1.34's monolithic
  `ext_proc_integration_test.cc`: the `two_ext_proc_filters_` config
  path and its helpers (`addDownstreamExtProcFilter`, `server1*` gRPC
  helpers), the extracted `initializeConfigDuplexStreamed`, the renamed
  header/body helpers, and the five new `TwoExtProcFilters*` tests.
- The `ServerSendOutOfOrderResponseDuplexStreamed` test kept 1.34's own
  400-response behavior; only the mechanical helper renames were applied
  (the 1.35 500-response variant was not adopted).
- The 1.35-only tests that appeared in the conflict but are unrelated to
  this feature (`DISABLED_DuplexStreamedServerResponseWithSynthesizedTrailer`,
  `BufferedModeOverSizeRequestLocalReply`,
  `FilterStateAccessLogSerialization`, and the other Pack*/*Trailers*
  tests) belong to other commits not backported to 1.34 and were dropped.

Signed-off-by: Jonh Wendell <[email protected]>
Co-authored-by: Claude Opus 4.8 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ext_proc: FULL DUPLEX STREAMED response body truncated when multiple filters defined

5 participants