Skip to content

http: add the proactive draining for tunneling streams - #47991

Merged
yanavlasov merged 1 commit into
envoyproxy:mainfrom
wbpcode:http-proactive-connection-drain
Oct 6, 2026
Merged

yanavlasov merged 1 commit into
envoyproxy:mainfrom
wbpcode:http-proactive-connection-drain

Conversation

@wbpcode

@wbpcode wbpcode commented Oct 3, 2026 •

Copy link
Copy Markdown
Member

Commit Message: http: add the proactive draining for tunneling streams
Additional Description:

With the connection-level drain path (envoy.reloadable_features.use_connection_event_drain), the HTTP connection manager only decides whether to drain a connection when it encodes a response. This leaves two gaps:

  • A connection that sends no response during the drain window (idle, low request rate, or only carrying long-lived streams such as WebSockets) never gets a GOAWAY or Connection: close. It stays open until the listener is torn down at the end of the drain window, together with every other connection like it, so their clients all reconnect at the same moment.
  • A connection that never rolled a drain-close can still receive a new request right before the deadline, which is then cut off mid-flight.

This PR keeps the response-time decision and adds a proactive stage on top of it. Using the defaults (--drain-time-s 600, HCM drain_timeout 5s):

t=0s            t=300s               t=400s                  t=595s  t=600s
 |---------------|--------------------|-----------------------|-------|
 drain starts    ramp reaches P=1     proactive window opens   window  listener
 onDrain()       (1/2 * drain_time)   (2/3 * drain_time)       closes  torn down
  1. t=0 to 300s: the gradual ramp now reaches probability one at half of the drain time instead of at its end (ramp_factor = 0.5 in Network::shouldDrainClose()). From then on every response drains its connection.
  2. t=0: onDrain() arms a per-connection timer at a random point in [2/3 * drain_time, drain_time - drain_timeout]. The upper bound leaves room for the HCM's own drain sequence to complete before the teardown.
  3. t=400s to 595s: when the timer fires, a connection that is still not draining starts its drain sequence (GOAWAY for HTTP/2 and HTTP/3; the HTTP/1 state machine as for the idle timeout). A connection without a codec, which never received any data, is closed directly.

To close #45250

Risk Level: mid. core code changes.
Testing: unit.
Docs Changes: added.
Release Notes: added.
Platform Specific Features: n/a.

@wbpcode

wbpcode commented Oct 3, 2026

Copy link
Copy Markdown
Member Author

/retest

@wbpcode

wbpcode commented Oct 3, 2026

Copy link
Copy Markdown
Member Author

cc @arkodg

@arko-oai

arko-oai commented Oct 5, 2026

Copy link
Copy Markdown

thanks for building this out @wbpcode, excited to see this land ! will mitigate the tcp reconnect storm during listener drains

@yanavlasov
yanavlasov merged commit 17a6f9d into envoyproxy:main Oct 6, 2026
27 checks passed
@wbpcode
wbpcode deleted the http-proactive-connection-drain branch October 6, 2026 02:22
bpalermo added a commit to bpalermo/aether that referenced this pull request Oct 10, 2026
…the two carried patches it contains are dropped (#980) (#1643)

The pin is one fact in three places and moves as one: envoy and envoy_api
(proxy/MODULE.bazel) and the envoyproxy/bazel-registry commit
(proxy/.bazelrc, 5db29c09de17218d24f58c665be38208284754d8), written by
scripts/bump-envoy-pin.sh. rules_python follows what the envoy module
requests (2.2.0 -> 2.3.3). The lockfile is refreshed.

Dropped, because Envoy 189f198 contains them:
- envoy-47743-udp-hot-restart-forwarding-netns (envoyproxy/envoy#47743,
  a644fc670e): the carried hunks reverse-apply cleanly to the snapshot.
- envoy-aether1022-exec-in-netns-thread-self (envoyproxy/envoy#47776,
  7d6ca3273c): the snapshot opens /proc/thread-self/ns/net. The carried
  fallback for kernels older than 3.17 and its per-thread model test go with
  it.

Kept, in the same order:
- 47740 (still open upstream): unchanged content, hunk positions refreshed.
- aether1050: replaced by the diff of its upstream pull request,
  envoyproxy/envoy#47834 at 72408727eb, docs and changelog dropped. Same
  source as before plus three counters,
  server.hot_restart_udp_forwarding_{datagrams,retries,dropped}; the test
  hunks no longer carry the 47743 test changes.
- aether1054: rebased over envoyproxy/envoy#47991, which rewrote
  ConnectionManagerImpl::onDrain() to drain idle connections proactively in
  the last third of the drain time. That arms nothing when the drain time
  leaves no room after the drain timeout (the chart's 10s with the default
  5s), so the carried idle HTTP/3 drain stays, armed beside it from
  armIdleHttp3DrainTimer(). Upstream's ProactiveDrain* tests notify the drain
  before a codec exists and turn the carried timer off; the carried gradual
  case now asserts both timers.
- aether1054b, aether1054c, aether1074, aether1126: unchanged content.

proxy/.bazelrc: envoyproxy/envoy#47806 removed the --@envoy//bazel:libc++
flag and the force_libcpp define, so both leave the libc++ config; nothing
else upstream removed from its own .bazelrc is required to go, and the rest
is kept as built before.

Refs #980


Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

Co-authored-by: Claude Opus 5.5 <[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.

support to drain upgraded HTTP connection like websocket

3 participants