Skip to content

http: track the observed end of stream per filter - #48556

Closed
wbpcode wants to merge 5 commits into
envoyproxy:mainfrom
wbpcode:dev-positional-observed-end-stream
Closed

wbpcode wants to merge 5 commits into
envoyproxy:mainfrom
wbpcode:dev-positional-observed-end-stream

Conversation

@wbpcode

@wbpcode wbpcode commented Oct 22, 2026

Copy link
Copy Markdown
Member

Commit Message: http: track the observed end of stream per filter

Additional Description:

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. Core filter manager end_stream handling.
Testing: unit.
Docs Changes: N/A
Release Notes: added.

@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: #48556 was opened by wbpcode.

see: more, trace.

…keep the ext_proc inject guard

Signed-off-by: wbpcode <[email protected]>
@yanavlasov

Copy link
Copy Markdown
Contributor

@paul-r-gall ^^^

@yanjunxiang-google

Copy link
Copy Markdown
Contributor

/assign @yanjunxiang-google

@wbpcode

wbpcode commented Nov 8, 2026

Copy link
Copy Markdown
Member Author

because all existing reviews happens on #48660, and we iterate a lot. I will close this.

@wbpcode wbpcode closed this Nov 8, 2026
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.

3 participants