Repository navigation
on_demand: disable recreateStream for successful on-demand VHDS - #47183
Conversation
31315de to
f268fdf
Compare
Commit Message: disable recreateStream for successful on-demand VHDS. Additional Description: This mirrors the on-demand CDS fix in envoyproxy#43163 for the VHDS path. Before this change, when OnDemandRouteUpdate::onRouteConfigUpdateCompletion resolved a previously-missing virtual host, recreateStream(nullptr) was invoked, which (a) re-runs the entire filter chain, double-triggering non-idempotent filters sitting before the on_demand filter, and (b) reaches ActiveStream::recreateStream -> Buffer::OwnedImpl::move on the buffered request body. That buffer can be a sub-iteration zombie when the downstream stream was reset while VHDS was in flight, producing a remote-reachable crash (fault at 0x0 inside move), the same null-deref signature as the ODCDS crash fixed by envoyproxy#43163. With this change the VHDS callback continues decoding the existing stream instead. To make continueDecoding route to the freshly-discovered virtual host, a new StreamFilterCallbacks method refreshRouteConfigSnapshot() re-snaps snapped_route_config_ from the route config provider. Without this re-snap the resumed router lookup resolves against the pre-VHDS snapshot taken at request start and 404s. The ODCDS sibling does not need this because cluster lookup goes through getThreadLocalCluster() per request rather than the per-stream route snapshot. The new path is gated by envoy.reloadable_features.on_demand_vhds_no_recreate_stream (default true), mirroring envoy.reloadable_features.on_demand_cluster_no_recreate_stream. Set the guard to false to restore the legacy recreate behavior. Risk Level: moderate, this is a guarded behavior change. Testing: unit (on_demand_filter_test), integration (vhds_integration_test). Docs Changes: n/a Release Notes: added (changelogs/current/behavior_changes) Platform Specific Features: n/a Signed-off-by: William Dauchy <[email protected]>
f268fdf to
c2b90da
Compare
adisuissa
left a comment
There was a problem hiding this comment.
Thanks, overall LGTM, but I'm not an expert here.
Left some high-level question and some minor comments.
| return; | ||
| } | ||
|
|
||
| if (Runtime::runtimeFeatureEnabled( |
There was a problem hiding this comment.
High-level question:
How will this impact a case where the OD-VHDS request is sent, but the response will timeout? (I believe that at the moment there's a bug in VHDS where the subscription doesn't time out, but that should probably be fixed)
There was a problem hiding this comment.
This change is neutral for the timeout case. The guard only affects the route_exists == true branch: it replaces recreateStream() with refreshRouteConfigSnapshot() + clearRouteCache() + a re-drive of decodeHeaders(), otherwise continueDecoding(). It does not change when the callback fires.
If the update completes with the host unresolved, route_exists == false and both the old and new paths call continueDecoding(). If the subscription never times out and the callback never fires, the request parks; that is true before and after this PR, since we do not touch the subscription lifecycle. So it is a pre-existing, separate issue. I agree the VHDS subscription timeout should be fixed on its own.
|
|
||
| // tests onRouteConfigUpdateCompletion() when redirect contains a body with trailers (fully read) | ||
| TEST_F(OnDemandFilterTest, OnRouteConfigUpdateCompletionRestartsActiveStreamWithTrailers) { | ||
| TestScopedRuntime scoped_runtime; |
There was a problem hiding this comment.
Are all these tests with disabled runtime-flag should be removed after the runtime flag is removed?
Seems a bit strange that the impact of changing a behavior is removal of many tests.
There was a problem hiding this comment.
They are not removed by this PR. They are pinned to guard-off so the existing recreateStream() expectations still hold while the new behavior is the default. The new behavior has its own permanent test, OnRouteConfigUpdateCompletionNoRecreateStream. When the guard is removed later, only the tests for the deleted legacy branch go away; guard-on coverage stays. Same pattern as #43163. I can collapse the guard-off cases to one representative test if you prefer.
| // the HCM filter chain. ``prependFilter`` inserts at the front of the list, | ||
| // so calling it with ``add-header-filter`` *after* ``on_demand`` leaves the | ||
| // final chain as: add-header-filter -> on_demand -> router. | ||
| class OnDemandVhdsRecreateStreamRegressionTest : public VhdsIntegrationTest { |
There was a problem hiding this comment.
Why is a new test suite needed in this case?
There was a problem hiding this comment.
The assertion needs a filter chain the base suite does not set up. It prepends on_demand then add-header-filter (chain: add-header-filter -> on_demand -> router) and counts how often x-header-to-add is stamped upstream: once means continueDecoding() (guard on), twice means recreateStream() (guard off). The base suite installs neither filter. The subclass keeps that setup isolated, matching #43163. I can inline it into VhdsIntegrationTest instead if you prefer.
|
Thanks. Replies inline. In short: the guard only changes the successful-resolution branch of onRouteConfigUpdateCompletion(), the disabled-flag tests are transitional coverage for the legacy path (as in #43163), and the new fixture is needed for a specific filter chain. Happy to adjust. |
|
ping @adisuissa |
| // --------------------------------------------------------------------------- | ||
| // Regression tests for the VHDS on-demand recreate-stream crash. | ||
| // | ||
| // OnDemandRouteUpdate::onRouteConfigUpdateCompletion (in | ||
| // source/extensions/filters/http/on_demand/on_demand_update.cc) historically | ||
| // called callbacks_->recreateStream(nullptr) when VHDS successfully resolved | ||
| // the host and the request body had been fully read. That recreate path ran | ||
| // ActiveStream::recreateStream at source/common/http/conn_manager_impl.cc | ||
| // which unconditionally dereferences filter_manager_.bufferedRequestData() | ||
| // via Buffer::OwnedImpl::move -- the same null-dereference signature as the ODCDS | ||
| // crash fixed by #43163 for the cluster-discovery path. |
There was a problem hiding this comment.
Seems we will check this null case?
const bool proxy_body = buffered_request_data != nullptr && buffered_request_data->length() > 0;
if (proxy_body) {
request_data->move(*buffered_request_data);
}
There was a problem hiding this comment.
I did a quick glance the tests self. Seems fine to me. Could you simplify these comments to only explain what cases are tested?
There was a problem hiding this comment.
Done in e1e7f74: each helper and test comment now only states the case it covers, and the class comment explains the add-header-filter counting once. Also dropped an unused buffer_impl.h include and its BUILD dep.
wbpcode
left a comment
There was a problem hiding this comment.
LGTM to the code. Seems reasonable to me. It's unnecessary to recreate the stream in this case.
Only comments to the tests. Thanks again. And please merge main because this PR is pending for a while.
/wait
| // --------------------------------------------------------------------------- | ||
| // Regression tests for the VHDS on-demand recreate-stream crash. | ||
| // | ||
| // OnDemandRouteUpdate::onRouteConfigUpdateCompletion (in | ||
| // source/extensions/filters/http/on_demand/on_demand_update.cc) historically | ||
| // called callbacks_->recreateStream(nullptr) when VHDS successfully resolved | ||
| // the host and the request body had been fully read. That recreate path ran | ||
| // ActiveStream::recreateStream at source/common/http/conn_manager_impl.cc | ||
| // which unconditionally dereferences filter_manager_.bufferedRequestData() | ||
| // via Buffer::OwnedImpl::move -- the same null-dereference signature as the ODCDS | ||
| // crash fixed by #43163 for the cluster-discovery path. |
There was a problem hiding this comment.
I did a quick glance the tests self. Seems fine to me. Could you simplify these comments to only explain what cases are tested?
…ecreate-stream Signed-off-by: William Dauchy <[email protected]>
Reduce the comments in OnDemandVhdsRecreateStreamRegressionTest to a description of the case each test covers. Drop the inaccurate note that recreateStream() unconditionally dereferences the buffered request data, and remove the unused buffer_impl.h include and buffer_lib dependency. Signed-off-by: William Dauchy <[email protected]>
Describe the change as avoiding a second run of the decoder filters before on_demand, and drop the claim about how moving the buffered request body could crash. Shorten the related source comment. Signed-off-by: William Dauchy <[email protected]>
|
Thanks. Merged main and simplified the test comments. I also reworded the rationale and in the PR description so it no longer claims a specific crash mechanism; the main point is that recreating the stream re-runs the filters before on_demand. on_demand_filter_test, vhds_integration_test and odcds_integration_test pass locally. |
|
/retest |
Signed-off-by: code <[email protected]>
|
/retest transients |
… route (#48079) Commit Message: on_demand: continue to the router when the on-demand VHDS virtual host has no matching route. Additional Description: After #47183, onRouteConfigUpdateCompletion() re-runs decodeHeaders() once VHDS reports that the virtual host exists. route_exists only means the virtual host exists, not that one of its routes matches the request. If none match, decodeHeaders() requests the same virtual host again. Since #46216 that repeated request is not sent, so the request waits until the stream idle timeout. Before #46216 it was sent and answered again, so the request looped on VHDS. The legacy recreateStream() path has the same problem. This change re-checks route() after refreshing the route config snapshot. route_exists now means a route was found, as the scoped RDS callback already reports. If no route matches, the filter continues to the router, which replies with a 404. Tradeoff: a virtual host that only gains the matching route in a later VHDS update is no longer picked up while the request waits. Upstream never answered this case before: the request looped or waited until the stream idle timeout. Related PRs: - #48000 answers repeated VHDS requests locally. With that change, the decodeHeaders() re-run would get an immediate answer for the same virtual host and request it again. Continuing to the router when no route matches avoids that. - #44401 lets a VHDS virtual host replace an RDS virtual host with the same name. If the VHDS copy also has no route for the request, the request currently waits until the stream idle timeout. With this change it gets a 404. Risk Level: Low. Guarded, limited to on-demand VHDS. Testing: New unit tests in on_demand_filter_test cover both values of the new guard and of on_demand_vhds_no_recreate_stream. New integration tests in vhds_integration_test cover both on_demand_vhds_no_recreate_stream values. Without the fix, the new tests with the guard enabled fail and the integration requests time out waiting for a response. on_demand_filter_test, vhds_integration_test, odcds_integration_test and on_demand_integration_test pass. Docs Changes: N/A Release Notes: Added under changelogs/current/bug_fixes. Platform Specific Features: N/A Runtime guard: envoy.reloadable_features.on_demand_vhds_require_route_match (default true). Set it to false to restore the previous behavior. AI assistance: Cursor helped trace the issue and write the tests. I reviewed and understand all changes. Signed-off-by: William Dauchy <[email protected]>
- Update ENVOY_COMMIT in MODULE.bazel to the latest Envoy commit, update bazel_dep versions to envoyproxy/envoy#48143, envoyproxy/envoy#48104, and refresh MODULE.bazel.lock - Update tools/code_format/config.yaml to envoyproxy/envoy#47183 - Update .github/config.yml to envoyproxy/envoy#48145, envoyproxy/envoy#48134, envoyproxy/envoy#47758 - Update .bazelversion to envoyproxy/envoy#48114 - Update .bazelrc to envoyproxy/envoy#48140, envoyproxy/envoy#48101, envoyproxy/envoy#47957 - Update tools/base/requirements.txt Signed-off-by: Jason Ye <[email protected]>
Commit Message: disable recreateStream for successful on-demand VHDS.
Additional Description:
This mirrors the on-demand CDS fix in #43163 for the VHDS path. Before this
change, when OnDemandRouteUpdate::onRouteConfigUpdateCompletion resolved a
previously-missing virtual host, recreateStream(nullptr) was invoked, which
re-runs the entire filter chain, so non-idempotent filters sitting before
the on_demand filter run twice. With this change the VHDS callback
continues decoding the existing stream instead. A crash in recreateStream()
on this path was also observed in production and is avoided as well.
To make continueDecoding route to the freshly-discovered virtual host, a new
StreamFilterCallbacks method refreshRouteConfigSnapshot() re-snaps
snapped_route_config_ from the route config provider. Without this re-snap
the resumed router lookup resolves against the pre-VHDS snapshot taken at
request start and 404s. The ODCDS sibling does not need this because cluster
lookup goes through getThreadLocalCluster() per request rather than the
per-stream route snapshot.
The new path is gated by
envoy.reloadable_features.on_demand_vhds_no_recreate_stream (default true),
mirroring envoy.reloadable_features.on_demand_cluster_no_recreate_stream.
Set the guard to false to restore the legacy recreate behavior.
Risk Level: moderate, this is a guarded behavior change.
Testing: unit (on_demand_filter_test), integration (vhds_integration_test).
Docs Changes: n/a
Release Notes: added (changelogs/current/behavior_changes)
Platform Specific Features: n/a