Skip to content

http: fix decoder filter local reply abort lifecycle in FilterManager. - #49102

Open
rblaze wants to merge 12 commits into
envoyproxy:mainfrom
rblaze:local_replies
Open

rblaze wants to merge 12 commits into
envoyproxy:mainfrom
rblaze:local_replies

Conversation

@rblaze

@rblaze rblaze commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Commit Message: http: fix decoder filter local reply abort lifecycle in FilterManager.
Additional Description: This is the first pull request in the chain that makes local replies from upstream HTTP filters retriable.

When a decoder filter aborts the chain with sendLocalReply, FilterManager::decodeHeaders ran the prepared local reply before finishing that filter's bookkeeping (processed_headers_, commonHandleAfterHeadersCallback(), and decodeComplete()), and FilterManager::decodeTrailers ran it before commonHandleAfterTrailersCallback(). Running the prepared local reply can complete the stream synchronously and destroy the filters, so decodeHeaders could call decodeComplete() on a filter after onDestroy(). The downstream HCM hits this today: a filter local reply in decodeHeaders(end_stream=true) that ends the stream got decodeComplete() after onDestroy(). HttpConnectionManagerImplTest.FilterHeadReply encoded that order and is updated.

Each filter's bookkeeping now finishes before executeLocalReplyIfPrepared() runs, and iteration returns right after it:

  • decodeData and decodeTrailers now clear filter_call_state_ (and decodeTrailers sets end_stream_ = true) before calling decodeComplete(), matching decodeHeaders.
  • decodeComplete() in decodeData, decodeTrailers, and the abort branch of decodeHeaders is guarded by !state_.destroyed_, so aborts that tear the stream down synchronously inside a decoder callback (for example ContinueAndResetStream, a direct local reply after response headers, or resetStream()) do not call into a destroyed filter.
  • The post-loop tails of decodeHeaders and decodeData also return early when state_.destroyed_ is set (for example when maybeContinueDecoding() or a 413 buffer-limit reply destroys the stream after the filter callback returned).

In decodeHeaders and decodeTrailers, the early return from the abort block now also covers the terminal decoder filter (which previously fell through to the end of both methods, whereas non-terminal filters already returned early) and removes the dead maybeContinueDecoding() calls on an already-aborted chain in decodeHeaders. Before returning, decodeHeaders and decodeData (when end_stream is set) and decodeTrailers still call disarmRequestTimeout() if !state_.destroyed_ and response headers have not been set, so aborts that do not encode local reply headers (such as graceful sendGoAwayAndClose) still disarm the request timeout on a completed request without disarming twice on local replies. Returning early on an aborted chain also skips:

  • processNewlyAddedMetadata() (which previously cleared added metadata for non-terminal filters in decodeTrailers, and on a header-only decodeHeaders abort caused the terminal filter to buffer a synthetic empty end_stream data frame);
  • the trailing maybeEndDecode() for the terminal filter (a stream whose decoder chain was aborted is closed once encoding finishes, the same as a completed one).

The "iteration aborted" trace log in decodeData and decodeTrailers now comes before the local reply runs, as in decodeHeaders.

The code in this PR is AI-generated (JetSki, Antigravity)

Risk Level: low
Testing: unit tests
Docs Changes: no
Release Notes: no
Platform Specific Features: no
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional API Considerations:]

@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: #49102 was opened by rblaze.

see: more, trace.

@rblaze

rblaze commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

/retest

@rblaze
rblaze force-pushed the local_replies branch 2 times, most recently from 387df02 to 17b72fe Compare November 9, 2026 18:43
When a decoder filter aborts the chain with `sendLocalReply`, `FilterManager::decodeHeaders` and `FilterManager::decodeTrailers` ran the prepared local reply before finishing that filter's bookkeeping (`processed_headers_`, the after-callback handling, and `decodeComplete()`). Running the prepared local reply can complete the stream synchronously and destroy the filters, so the old order could call `decodeComplete()` on a filter after `onDestroy()`. The downstream HCM hits this today: a filter local reply in `decodeHeaders(end_stream=true)` that ends the stream got `decodeComplete()` after `onDestroy()`. `HttpConnectionManagerImplTest.FilterHeadReply` encoded that order and is updated.

The filter's bookkeeping now finishes before `executeLocalReplyIfPrepared()` runs, and iteration returns right after it. `decodeData` already had the safe order. `decodeComplete()` in the abort branch of `decodeHeaders` is also guarded by `!state_.destroyed_`, so aborts that tear the stream down synchronously inside `decodeHeaders` (for example `ContinueAndResetStream`, a direct local reply after response headers, or `resetStream()`) do not call into a destroyed filter either.

In `decodeHeaders`, the early return now also covers the terminal decoder filter (on the downstream path, router local replies such as "no route" or "no healthy upstream"), which used to fall through to the end of `decodeHeaders`, as non-terminal filters already did. In `decodeTrailers`, the early return is new for every aborting filter, terminal or not. Both skip work that is not needed after a local reply:
- the pass over metadata the filter added before the local reply. This was already a no-op, since `decodeMetadata` stops on an aborted chain and the pass only cleared the added metadata;
- the trailing `disarmRequestTimeout()`, which ran a second time because encoding the local reply headers already disarms the request timeout;
- in `decodeHeaders`, the trailing `maybeEndDecode()`, which only marks the decoder chain complete. A stream whose decoder chain was aborted is closed once encoding finishes, the same as a completed one.

The "iteration aborted" trace log in `decodeTrailers` now comes before the local reply runs, as in `decodeHeaders`.

Signed-off-by: Andrey Sverdlichenko <blazered@google.com>
@rblaze
rblaze marked this pull request as ready for review November 9, 2026 20:09
@rblaze

rblaze commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

/retest

@rblaze

rblaze commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

/assign @paul-r-gall

Comment thread source/common/http/filter_manager.cc Resolved
Comment thread source/common/http/filter_manager.cc Resolved
Signed-off-by: Andrey Sverdlichenko <blazered@google.com>
Signed-off-by: Andrey Sverdlichenko <blazered@google.com>
@rblaze

rblaze commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the comments and did similar changes in another place. PTAL.

@rblaze

rblaze commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

/retest

@paul-r-gall

Copy link
Copy Markdown
Contributor

please merge main, thanks.

Signed-off-by: Andrey Sverdlichenko <blazered@google.com>

# Conflicts:
#	source/common/http/filter_manager.cc
#	test/common/http/filter_manager_test.cc
…decodeData.

Signed-off-by: Andrey Sverdlichenko <blazered@google.com>
Signed-off-by: Andrey Sverdlichenko <blazered@google.com>
…n local reply.

Signed-off-by: Andrey Sverdlichenko <blazered@google.com>
…ing.

Signed-off-by: Andrey Sverdlichenko <blazered@google.com>
Signed-off-by: Andrey Sverdlichenko <blazered@google.com>
@rblaze

rblaze commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

/retest

@paul-r-gall paul-r-gall 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.

very close now.

Comment thread source/common/http/filter_manager.cc Resolved
Comment thread test/common/http/filter_manager_test.cc Resolved
Comment thread test/common/http/filter_manager_test.cc Resolved
Comment thread test/common/http/filter_manager_test.cc Resolved
Comment thread source/common/http/filter_manager.cc Resolved
…t helpers.

Signed-off-by: Andrey Sverdlichenko <blazered@google.com>
paul-r-gall
paul-r-gall previously approved these changes Nov 17, 2026
@paul-r-gall

Copy link
Copy Markdown
Contributor

/assign-from envoyproxy/senior-maintainers

@repokitteh-read-only

Copy link
Copy Markdown

envoyproxy/senior-maintainers assignee is @nezdolik

🐱

Caused by: a #49102 (comment) was created by @paul-r-gall.

see: more, trace.

Signed-off-by: Andrey Sverdlichenko <blazered@google.com>

@botengyao botengyao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thanks for the fix! lgtm module one question here, and here is the proposed change

/wait

@rblaze

rblaze commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

/retest

Signed-off-by: Andrey Sverdlichenko <blazered@google.com>

This branch has not been deployed

No deployments
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.

4 participants