Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate state for tracking downstream end_stream in filter manager and HCM #35815

Merged
merged 3 commits into from
Aug 23, 2024

Conversation

yanavlasov
Copy link
Contributor

@yanavlasov yanavlasov commented Aug 22, 2024

Commit Message:
Fix two bugs in processing of deferred requests.

  1. Filter manager (FM) uses presence of the timestamp of receipt of the downstream end_stream to set the end_stream during filter chain resumption. If a complete request (with end_stream= true) was deferred, its filter chain iteration would start with the downstream end_stream flag set. If there is a decoder filter that pauses and resumes filer chain iteration, all filters after resumption will see end_stream as true.

For example if a filter pauses in decodeHeaders() and then resumes in decodeData() all filters after that will have decodeHeaders() called with end_stream == true. This can cause request to be proxied by the router without the body.

  1. The request trailers were also immediately available to filter manager when processing of a deferred request begins. If there is a filter that pauses and resumes iteration it makes filter manager incorrectly process trailers as though they were added by the filter that paused iteration. This causes trailers to be processed by filter chain twice triggering asserts.

The same problem is also present when HCM recreates the stream with body (i.e. for internal redirect).

This change makes filter manager use its own, already existing, flag observed_decode_end_stream_ for tracking state of downstream end_stream flag when resuming the filter chain, instead of the timestamp of the end_stream receipt from downstream client.

HCM continues to use the presence of the end_stream timestamp as the indicator of completed client's stream.

This change can be reverted by setting the envoy.reloadable_features.use_filter_manager_state_for_downstream_end_stream runtime flag to false.

Risk Level: Medium, affects deferred request processing
Testing: Unit tests
Docs Changes: N/A
Release Notes: Yes
Platform Specific Features: N/A
Runtime guard: envoy.reloadable_features.use_filter_manager_state_for_downstream_end_stream
Fixes #35814

Copy link

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

🐱

Caused by: #35815 was opened by yanavlasov.

see: more, trace.

Copy link
Contributor

@RyanTheOptimist RyanTheOptimist left a comment

Choose a reason for hiding this comment

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

Wow, great catch! LGTM

} else {
// Save trailers in a different variable since `request_trailers_` is available to the filter
// manager via `requestTrailers()` callback and makes filter manager see trailers prematurely
// when deferred request is processed.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice comment! Thanks for adding this.

@yanavlasov yanavlasov enabled auto-merge (squash) August 23, 2024 13:14
Signed-off-by: Yan Avlasov <[email protected]>
KBaichoo
KBaichoo previously approved these changes Aug 23, 2024
Copy link
Contributor

@KBaichoo KBaichoo left a comment

Choose a reason for hiding this comment

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

Nice work!

Signed-off-by: Yan Avlasov <[email protected]>
@yanavlasov yanavlasov merged commit 09501db into envoyproxy:main Aug 23, 2024
47 checks passed
@yanavlasov yanavlasov deleted the fix-deferred-end-stream branch August 23, 2024 17:01
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.

Deferred requests with body or trailers can be proxied incomplete
3 participants