Repository navigation
proxy: carried patch — non-blocking hot-restart UDP forwarding and bounded child receives (#1050) - #1060
Merged
Conversation
…unded child receives (#1050) Carries envoy-aether1050-hotrestart-nonblocking-forward.patch on the 726d7ac pin, after 47743. The hot-restart parent forwarded undispatchable UDP/QUIC packets to the child from its main thread with a blocking sendmsg(); the child's main thread waited for the parent's replies (stats merge every flush, listen socket hand-offs) with a blocking recvmsg() and read no forwarded packets meanwhile. Once the child's socket filled, both main threads waited on each other for good (#1050). The patch makes parent forwarding a bounded non-blocking queue retried on a 2 ms timer (dropped when full or when the child is gone), makes the child keep servicing forwarded packets while it waits for a reply, probe the parent for liveness and give up after a bounded deadline, and gives the domain sockets send/receive timeouts so no blocking call can hang. The wire protocol is unchanged. Its tests (the child test's ServicesUdpForwardingWhileWaitingForParentStats is the deadlock interleaving, red without the patch) run from //bazel/patches:carried_patch_tests; the patch also brings the 47743 test hunks those files need to compile against the 47743 source. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01WyMzptZ12rAgMW8cXtKqE4 Signed-off-by: Bruno Palermo <[email protected]>
Owner
Author
Kind red/green (workaround off:
|
| run | proxy | freeze | restarts | wedges | client non-200 |
|---|---|---|---|---|---|
| RED | unpatched (pinned sha256:edb75ef3…) |
6 s | 4 | 3/4 (stacks = #1050) | 1,702 000 + 4,143 503 of ~264k |
| GREEN | patched (c62afa5) | 6 s | 8 | 0/8 | 679 000 + 7 503 of 491k (timeouts on new QUIC conns while the harness froze the child) |
| unforced | patched | none | 10 | 0/10 | 0 of 541k |
| stress | patched | 12 s | 3 | 0/3 | 556 000 + 5 503 of 196k |
- Mixed-version first roll (unpatched epoch 0 → patched epoch 1, cross-pod) clean.
- Parent stats merge restored:
server.hot_restart_generation+1 per epoch; child showedserver.parent_connections54→36→35→0 during drain,server.total_connections108 (own + parent); parent-onlydownstream_cx_drain_closecounters merged into the child. - None of the patch's diagnostic lines fired in any run, even at a 12 s freeze: the 1 MiB queue absorbed it and EAGAIN retries leave no trace. The drop/unresponsive/gone branches are proven only by the unit tests. Suggest a counter for queued/retried/dropped forwarded datagrams so a soak can see the path.
- Harness needed two changes to run this (not in this PR yet):
EWQ_LOCAL_PROXY=1ine2e/eastwest-quic.shto load a locally built proxy image, ande2e/hotrestart-wedge.shreading per-pod status files before killing the load (theload-*.txtsummaries were always empty).
🤖 Generated with Claude Code
bpalermo
marked this pull request as ready for review
September 28, 2026 20:30
This was referenced Sep 28, 2026
bpalermo
added a commit
that referenced
this pull request
Sep 28, 2026
…ion outlives a hot-restart parent (#1054); skipParentStats default off now that #1060 fixes the deadlock (#1063) - chart: proxy.hotRestart.drainStrategy (immediate|gradual, default immediate) rendered as --envoy-arg=--drain-strategy <v>; validated. - agent: --east-west-quic-idle-timeout (default 8s) sets the idle timeout on the quic: twins only; h1/h2 keep 30s. The chart fills it from agent.eastWestQuicIdleTimeout and fails the render unless idle + 5s < proxy.hotRestart.parentShutdownTime. - chart: proxy.hotRestart.skipParentStats defaults to false (the carried #1060 patch fixes the deadlock); kept as an emergency switch. - e2e: HR_MODE=sparse in eastwest-quic-hotrestart.sh (two nodes via EWQ_WORKER=1, optional forced parent freeze), EWQ_LOCAL_PROXY, wedge harness reads per-pod status files before killing load. - docs: runbook section and soak gate for #1054. Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr Co-authored-by: Claude Opus 5.5 <[email protected]>
This was referenced Sep 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Carries a patch on the 726d7ac pin that removes the hot-restart main-thread deadlock from #1050, as the real fix behind the
--skip-hot-restart-parent-statsworkaround shipped in rev250. Not proposed upstream from here; that is the maintainer's call (see "Upstreaming" below).The deadlock
Both halves are in Envoy as pinned (unchanged on
maind0b811f):drainParentListeners(), every UDP/QUIC packet no parent session owns is posted to the parent's main thread and sent to the child over the_udpAF_UNIX datagram socket withRpcStream::sendHotRestartMessage, which flips the socket to blocking and callssendmsg()with no timeout. The child's inherited UDP listeners stay paused until the parent terminates, so all new QUIC traffic takes this path for the whole--parent-shutdown-time-swindow.mergeParentStatsIfAny → getParentStats → receiveHotRestartMessage(Blocking::Yes)on the child's main thread, with no timeout, and reads nothing from the_udpsocket while it waits.duplicateParentListenSocket(a listener added during the window) has the same shape.Once the child's
_udpsocket queue is full, the parent's main thread is parked insendmsg()and never reads the child's Stats request; the child's main thread is parked inrecvmsg()and never drains the_udpsocket. Each waits on the other for good: admin, xDS, timers and signal handling are dead in both processes, SIGTERM cannot land, and the workers keep serving. This path has existed since Envoy added UDP hot-restart forwarding (envoyproxy/envoy#29585, 2023); enabling h3 across many per-pod UDP listeners is what puts enough traffic through it to fill the socket.The patch (
proxy/bazel/patches/envoy-aether1050-hotrestart-nonblocking-forward.patch)Applied after 47743 (same files). Wire protocol unchanged: no proto change,
HOT_RESTART_VERSIONunchanged, so it hot-restarts across an unpatched parent (first roll) and an unpatched child (rollback).Parent: forwarding never blocks.
HotRestartingParent::sendHotRestartMessage(theNonDispatchedUdpPacketHandlersink) now appends the message's datagrams, all or none, to a bounded (1 MiB) send queue on the UDP stream and flushes it with non-blockingsendmsg(MSG_DONTWAIT).EAGAIN/ENOBUFSleave the rest queued and arm a 2 ms retry timer on the main dispatcher; a full queue drops the new packet (QUIC retransmits);ECONNREFUSED(child gone) drops the queue. The blocking-mode toggle, the 10×1 sECONNREFUSEDsleep-retry and theRELEASE_ASSERTare all off this path: a dead child can no longer stall the parent's main thread for 10 s and then crash it.Child: waiting for a reply keeps the forwarding flowing, and is bounded. All three request/reply exchanges (
getParentStats,duplicateParentListenSocket,sendParentAdminShutdownRequest) go throughwaitForParentReply(): receive in 10 ms slices (SO_RCVTIMEO), and between slices drain the_udpsocket with the sameonSocketEventUdpForwarding()the file event uses (packets are handed to the worker routers, thread-safe, as today). So the parent's blocking send always completes even against an unpatched parent, which is what breaks the cycle on the first roll. The wait is bounded by a 30 s deadline and a 1 s liveness probe (TestConnection, which the pinned parent already handles by ignoring it):sendParentTerminateRequeststill fires at the end of the drain period (which also completes the drains as before). The late reply is never consumed, so a mismatched reply type cannot trip the existingRELEASE_ASSERTs.ECONNREFUSED: the parent process is gone): the parent is written off as gone: the drains complete immediately (inherited UDP listeners unpause, assendParentTerminateRequestwould do) and the stat merger is finalized.drainParentListenersandsendParentTerminateRequest(no reply expected) send withallow_failure, so a parent that is gone no longer makes the child sleep 10 s and abort.RpcStream. Both domain sockets get
SO_SNDTIMEO= 1 s andSO_RCVTIMEO= 10 ms at bind. A blocking receive returns null after its slice instead of asserting (partial message stays buffered, the stream state is untouched); a blocking send returnsTimedOutinstead of hanging, so a parent reply to a child that stopped reading is abandoned after 1 s per datagram.sendHotRestartMessagekeeps its bool contract;trySendHotRestartMessagereportsSent/ConnectionRefused/TimedOutfor the probe.Not changed: the child's
ECONNREFUSEDsleep-retry-then-assert on its requests (startup handshake) keeps its pre-patch semantics; only replies and fire-and-forget messages changed.How the test proves it
test/server/hot_restarting_child_test.cc,HotRestartingChildWaitingForParentTest.ServicesUdpForwardingWhileWaitingForParentStats, encodes the dependency itself in the syscall mock: the parent's Stats reply becomes readable on the main socket only after the forwarded packet has been read from the_udpsocket (that is the parent's blockedsendmsgcompleting). The test callsgetParentStats()and asserts the packet was delivered to the worker router and the reply merged.EAGAIN, which the pre-patch code treats as fatal:assert failure: recv_result.return_value_ != -1 … recvmsg() returned -1, errno = 11(verified red by re-running the suite with the oldBlocking::Yessemantics restored). In production that same interleaving is the wedge rather than an abort because the real socket blocks forever instead of returning.Parent side (
hot_restarting_parent_test.cc,HotRestartingParentUdpForwardingTest): forwarding leaves the socket non-blocking;EAGAINqueues and arms the 2 ms timer, the retry sends the backlog in order; a multi-datagram message is queued whole and not split by a would-block;ECONNREFUSEDdrops the queue with no timer, no sleep, no assert; a full queue drops new packets with a periodic warning. Base (hot_restarting_base_test.cc): a timed-out send fails without asserting; a timed-out blocking receive returns null.All four
@envoy//test/serverhot-restart targets are wired into//bazel/patches:carried_patch_tests. The patch also carries the 47743 test hunks these files need (the 47743 patch dropped them), so the suite compiles against the 47743 source.Envoy's end-to-end
//test/integration:hotrestart_test(real parent/child processes, real sockets and timeouts) was run on the patched tree and passes.What the wedge harness should show
e2e/hotrestart-wedge.shwithWEDGE_FREEZE_S=6, without--skip-hot-restart-parent-stats: 0 wedges (was 4/4). Expected log lines during a roll, if any:hot restart udp forwarding queue is full(parent, only under a real burst),hot restart parent is unresponsive/is gone(child, only if the parent really stops answering). Neither should appear in a healthy roll. Worth also confirming thatserver.hot_restart_generationstill accumulates and that the child's stats merge (--skip-hot-restart-parent-statsoff) shows the parent's counters, since the merge path is exercised again.Upstreaming
This is a behavior change on the hot-restart protocol paths and would need a changelog entry and probably a runtime guard for an upstream PR; the wire protocol is unchanged. The maintainer decides whether and when to propose it.
🤖 Generated with Claude Code
https://claude.ai/code/session_01WyMzptZ12rAgMW8cXtKqE4