Skip to content

router: remove allow_multiplexed_upstream_half_close, keep half close for TCP upstreams - #48648

Merged
yanavlasov merged 1 commit into
envoyproxy:mainfrom
wdauchy:wdauchy/remove-multiplexed-upstream-half-close
Oct 30, 2026
Merged

yanavlasov merged 1 commit into
envoyproxy:mainfrom
wdauchy:wdauchy/remove-multiplexed-upstream-half-close

Conversation

@wdauchy

@wdauchy wdauchy commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Commit Message: router: remove allow_multiplexed_upstream_half_close, keep half close for TCP upstreams

Remove the envoy.reloadable_features.allow_multiplexed_upstream_half_close runtime guard. HTTP upstreams no longer half close before the downstream, so the compensating resets in the HTTP/1 codec and in TcpUpstream are removed.

Half close is kept for TCP upstreams with an HTTP/2 or HTTP/3 downstream, where END_STREAM maps to a TCP FIN (RFC 9113 §8.5). HTTP/1 downstreams can only end a CONNECT response by closing the connection, so they keep the reset. The router enables it per stream when the conn pool supports it (GenericConnPool::supportsIndependentHalfClose()), through the new DownstreamStreamFilterCallbacks::enableHalfClose().

Additional Description:
Follows @yanavlasov's proposal in #48316 to remove the flag. TCP tunnels still need half close: without it, an origin that FINs after a download resets the stream and the client gets a truncated body (#47378). This supersedes the TCP part of #47378 (cc @fl0Lec) and makes #48316 unnecessary.

The decision uses the conn pool, not the route: the http upstream factory ignores the requested protocol, so a CONNECT route can still reach an HTTP/1 upstream (the #48316 crash path).

Risk Level: Medium. TCP tunnels now end with an end of stream instead of a reset when the upstream half closes first. Revert with envoy.reloadable_features.tcp_tunnel_allow_upstream_half_close=false.
Testing: Router unit tests, and ConnectTerminationIntegrationTest.UpstreamHalfCloseKeepsTunnelOpen / UpstreamCloseWithHalfCloseDisabled. Tests that only covered HTTP upstream half close are removed.
Docs Changes: HTTP lifecycle in http_connection_management.rst and life_of_a_request.rst.
Release Notes: Added.
Platform Specific Features: N/A
Runtime guard: envoy.reloadable_features.tcp_tunnel_allow_upstream_half_close

AI assistance: prepared with AI assistance (Cursor agent). We reviewed and understand all of it.

@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: #48648 was opened by wdauchy.

see: more, trace.

@wdauchy
wdauchy force-pushed the wdauchy/remove-multiplexed-upstream-half-close branch 5 times, most recently from 56f42ba to 6ba9a12 Compare October 24, 2026 08:29
@wdauchy

wdauchy commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

/retest

@wdauchy

wdauchy commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

@phlax the format failure here (ImportError: cannot import name 'version' from 'packaging', https://github.com/envoyproxy/envoy/actions/runs/40078303704, both attempts) is a remote cache hit for //tools/code:checked. It comes from an earlier run on the same tree (the cancelled run https://github.com/envoyproxy/envoy/actions/runs/40078213656), and the earlier push passed in https://github.com/envoyproxy/envoy/actions/runs/40075523697. Since the genrule swallows failures with || :, a broken run got cached and is replayed for this tree. Proposed fix: #48654.

@wdauchy
wdauchy force-pushed the wdauchy/remove-multiplexed-upstream-half-close branch from 6ba9a12 to 244fbfc Compare October 24, 2026 11:18
@wdauchy

wdauchy commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

/retest

@wdauchy
wdauchy marked this pull request as ready for review October 24, 2026 12:15
@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: #48648 was ready_for_review by wdauchy.

see: more, trace.

phlax pushed a commit that referenced this pull request Oct 24, 2026
Commit Message: tools/code: Run the code check in `check_test` directly

Additional Description:
The `//tools/code:checked` genrule ran the code checker with `|| :`, so
a crash of the checker was a successful action. Its cache key only
changes with `//bazel:volatile-scm-hash`, so a cached crash is replayed
by every later run on the same tree.

On #48648, both attempts of
https://github.com/envoyproxy/envoy/actions/runs/40078303704 failed
`//tools/code:check_test` with identical output (`ImportError: cannot
import name 'version' from 'packaging'`), with `checked` served from the
remote cache. The only earlier run on that tree,
https://github.com/envoyproxy/envoy/actions/runs/40078213656, was
cancelled during that test. How the checker crashed there is not
confirmed.

This removes the genrule and runs the checker in `check_test` directly.
The test fails if the checker exits non-zero or prints anything. Failed
test results are not cached, so a crash is retried on the next run, and
passing results are still cached on the same key.

Risk Level: Low (CI only)
Testing: `buildifier` on `tools/code/BUILD`. Not built locally; relying
on the `format` job of this PR.
Docs Changes: N/A
Release Notes: N/A
Platform Specific Features: N/A

AI assistance: prepared with AI assistance (Cursor agent). We reviewed
and understand all of it.

---------

Signed-off-by: William Dauchy <[email protected]>
… for TCP upstreams

Remove the envoy.reloadable_features.allow_multiplexed_upstream_half_close
runtime guard. HTTP upstreams no longer half close the stream before the
downstream, so the compensating resets in the HTTP/1 codec and in TcpUpstream
go away.

Independent half close is kept for TCP upstreams with an HTTP/2 or HTTP/3
downstream, where END_STREAM maps to a TCP FIN (RFC 9113 section 8.5). The
router enables it per stream when the conn pool supports it, through
DownstreamStreamFilterCallbacks::enableHalfClose(). HTTP/1 downstreams can only
end a CONNECT response by closing the connection, so they keep the reset. It is
guarded by envoy.reloadable_features.tcp_tunnel_allow_upstream_half_close, on by
default.

Signed-off-by: William Dauchy <[email protected]>
@wdauchy
wdauchy force-pushed the wdauchy/remove-multiplexed-upstream-half-close branch from 244fbfc to a10fdee Compare October 24, 2026 13:08
@wdauchy

wdauchy commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

/retest

"envoy.reloadable_features.tcp_tunnel_allow_upstream_half_close")) {
return;
}
// HTTP/1 can only signal the end of a CONNECT response by closing the connection.

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.

I think technically server can half-close its end of the tunnel in H/1 case. But we can deal with this later.

@yanavlasov
yanavlasov merged commit 3a0fd51 into envoyproxy:main Oct 30, 2026
27 checks passed
@n0v1

n0v1 commented Nov 2, 2026 •

Copy link
Copy Markdown

This also removes the fix for #30149, which was a gRPC report, and we still depend on it for bidirectional gRPC streaming. A gRPC server may send its status before the client half-closes, for example to fail a long-lived bidi call on an invalid request. Without independent half close, Envoy resets the downstream stream as soon as the upstream completes. Response data still waiting for the client's flow-control window and the trailers with the status, are then lost.

We reproduced this with an HTTP/2 upstream that sends 2 MB plus grpc-status: 2 without waiting for the client's half close, and a client that reads slowly:

Envoy allow_multiplexed_upstream_half_close Client receives
1.37.2 (reset_with_error: false) true 2 MB + status
1.37.2 (reset_with_error: false) unset 1 KB, then RST_STREAM NO_ERROR, no status
1.40.2 true 2 MB + status
1.40.2 unset RST_STREAM INTERNAL_ERROR, no data, no status

RFC 9113 §8.1 allows a reset after a complete response, but here it cuts the response short, so clients rightly report an error.

Could independent half close be kept for HTTP/2 and HTTP/3 upstreams, at least behind a guard like the new tcp_tunnel_allow_upstream_half_close? Otherwise we can't upgrade beyond 1.40.

Update: #48857 (fixing #48192) would most likely fix this too: it defers the reset until the response has been fully encoded, which covers exactly the "unset" rows above. With that change, independent half close would no longer be needed for HTTP/2 upstreams, so removing the flag would be fine for us, as long as #48857 lands in the same release as this PR.

domolitom added a commit to domolitom/envoy that referenced this pull request Nov 10, 2026
- encodeTrailersBase(): with http2_deferred_reset_waits_for_end_stream, call
  onLocalEndStream() for empty trailers too, so a deferred reset that waits
  for END_STREAM is bounded by the stream flush timeout. Add codec tests for
  the timeout and for the guard-disabled behavior.
- OnlyStreamWithEndStreamSentIsReset: stop the loop once stream 2 is reset,
  as the stream frees the scheduled callback when it closes.
- Pass lambdas directly instead of testing::Invoke/InvokeWithoutArgs, which
  main removed in envoyproxy#48804.
- ConnectTerminationLargeResponseIntegrationTest: disable
  tcp_tunnel_allow_upstream_half_close (envoyproxy#48648), as with half close the
  upstream FIN ends the stream instead of resetting it.
- Add MultiplexedIntegrationTest.LargeUpstreamResponseBeforeRequestCompleteSmallWindow:
  a non-CONNECT HTTP/2 stream whose response completes before the request,
  with the response blocked by flow control. It fails without the fix.

Signed-off-by: Oliver Domokos <[email protected]>
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