Skip to content

Fix an issue with ext_proc filter configured in the upstream filter chain#41879

Merged
botengyao merged 12 commits intoenvoyproxy:mainfrom
yanjunxiang-google:upstream_route_retry
Nov 21, 2025
Merged

Fix an issue with ext_proc filter configured in the upstream filter chain#41879
botengyao merged 12 commits intoenvoyproxy:mainfrom
yanjunxiang-google:upstream_route_retry

Conversation

@yanjunxiang-google
Copy link
Copy Markdown
Contributor

@yanjunxiang-google yanjunxiang-google commented Nov 6, 2025

Fixes an issue when an HTTP filter is in the upstream filter chain, and its encodeHeaders() method is returning StopIteration() , and route retry policy is configured with retry on 5xx. In this case, when a 503 response is received, onUpstreamHeaders() will be called first, and the UpstreamRequest object will be removed from the upstream_request_ list. onUpstreamData() will be called right after, and should just return.

chain

Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
@yanjunxiang-google
Copy link
Copy Markdown
Contributor Author

/assign @yanavlasov @adisuissa @botengyao

Copy link
Copy Markdown
Member

@phlax phlax left a comment

Choose a reason for hiding this comment

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

could you add a changelog please

Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
@yanjunxiang-google
Copy link
Copy Markdown
Contributor Author

/retest

…eam_route_retry

Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
…eam_route_retry

Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
Comment thread source/common/router/router.cc Outdated
// and it's encodeHeaders() is returning FilterHeadersStatus::StopIteration.
// In this case, onUpstreamData() might get called with
// upstream_requests_.size() == 0 and we should just return.
if (upstream_requests_.size() != 1) {
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.

The original assertion implies the value must be 1, whereas the comment says it could be 0 or 1.
If that's the case, and assuming that 0 is a valid value, then it may be better to do the following:

// Explain when the size can be 0.
if (upstream_requests_.size() == 0) {
  // Consider adding another assertion that captures when this can occur.
  return;
}
// Explain why the size can only be 1 at this point.
ASSERT(upstream_requests_.size() == 1);

Copy link
Copy Markdown
Contributor Author

@yanjunxiang-google yanjunxiang-google Nov 7, 2025

Choose a reason for hiding this comment

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

Good idea, Done! For adding an assertion under size() == 0, my thought is that the upstream_request is already gone in that case, we probably should just return.

Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
@yanjunxiang-google
Copy link
Copy Markdown
Contributor Author

/retest

@yanavlasov
Copy link
Copy Markdown
Contributor

Would you be able to add a test to the https://github.com/envoyproxy/envoy/blob/main/test/integration/upstream_http_filter_integration_test.cc so that common functionality does not depend on a test in ext_proc extension, please? It is possible that https://github.com/envoyproxy/envoy/blob/main/test/integration/filters/encode_headers_return_stop_all_filter.cc could be used.

/wait-any

Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
@yanjunxiang-google
Copy link
Copy Markdown
Contributor Author

Would you be able to add a test to the https://github.com/envoyproxy/envoy/blob/main/test/integration/upstream_http_filter_integration_test.cc so that common functionality does not depend on a test in ext_proc extension, please? It is possible that https://github.com/envoyproxy/envoy/blob/main/test/integration/filters/encode_headers_return_stop_all_filter.cc could be used.

/wait-any

Good idea, done!
encode_headers_return_stop_all_filter.cc has some specific logic for that filter, which is not relevant to this issue. Therefore, I added a very simple pass through filter, only difference is returning StopIteration in it's encodeHeaders() method, to facilitate the tests.

@yanjunxiang-google
Copy link
Copy Markdown
Contributor Author

/retest

2 similar comments
@yanjunxiang-google
Copy link
Copy Markdown
Contributor Author

/retest

@yanjunxiang-google
Copy link
Copy Markdown
Contributor Author

/retest

Copy link
Copy Markdown
Contributor

@adisuissa adisuissa left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@adisuissa
Copy link
Copy Markdown
Contributor

/retest

…eam_route_retry

Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
Copy link
Copy Markdown
Member

@tyxia tyxia left a comment

Choose a reason for hiding this comment

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

Thanks!

Comment thread source/common/router/router.cc
@yanjunxiang-google
Copy link
Copy Markdown
Contributor Author

/retest

2 similar comments
@yanjunxiang-google
Copy link
Copy Markdown
Contributor Author

/retest

@yanjunxiang-google
Copy link
Copy Markdown
Contributor Author

/retest

@yanjunxiang-google
Copy link
Copy Markdown
Contributor Author

kind ping

@yanjunxiang-google
Copy link
Copy Markdown
Contributor Author

/retest

@yanjunxiang-google
Copy link
Copy Markdown
Contributor Author

Kind ping! The Publish and verify CI failure seems not related to the PR.

@botengyao
Copy link
Copy Markdown
Member

/retest

@phlax
Copy link
Copy Markdown
Member

phlax commented Nov 18, 2025

verify issue is fixed on main - main merge would resolve - but we can just push past it i think

…eam_route_retry

Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
@yanjunxiang-google
Copy link
Copy Markdown
Contributor Author

/retest

@agrawroh
Copy link
Copy Markdown
Member

I think CodeQL is failing across the board recently. Good that it's not a merge blocker.

@phlax
Copy link
Copy Markdown
Member

phlax commented Nov 18, 2025

i think its fixed on main

@yanjunxiang-google
Copy link
Copy Markdown
Contributor Author

/retest

…eam_route_retry

Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
@yanjunxiang-google
Copy link
Copy Markdown
Contributor Author

@phlax merge upstream still can not fix the CodeQL CI error.

@phlax
Copy link
Copy Markdown
Member

phlax commented Nov 18, 2025

apologies - see #42106 - ill look at it first thing tomorrow

…eam_route_retry

Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
@yanjunxiang-google
Copy link
Copy Markdown
Contributor Author

/retest

1 similar comment
@yanjunxiang-google
Copy link
Copy Markdown
Contributor Author

/retest

@yanjunxiang-google
Copy link
Copy Markdown
Contributor Author

yanjunxiang-google commented Nov 21, 2025

Thanks @phlax ! The CI now passed.

@botengyao botengyao merged commit 7d3c91c into envoyproxy:main Nov 21, 2025
25 checks passed
grnmeira pushed a commit to grnmeira/envoy that referenced this pull request Mar 20, 2026
…upstream filter chain (envoyproxy#41879)

Fixes an issue when an HTTP filter is in the upstream filter chain, and
its encodeHeaders() method is returning StopIteration() , and route
retry policy is configured with retry on 5xx. In this case, when a 503
response is received, onUpstreamHeaders() will be called first, and the
UpstreamRequest object will be removed from the upstream_request_ list.
onUpstreamData() will be called right after, and should just return.

---------

Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
Signed-off-by: Gustavo <grnmeira@gmail.com>
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.

7 participants