Skip to content

proxy: carried patch — non-blocking hot-restart UDP forwarding and bounded child receives (#1050) - #1060

Merged
bpalermo merged 1 commit into
mainfrom
proxy/1050-hotrestart-nonblocking-forward
Sep 28, 2026
Merged

bpalermo merged 1 commit into
mainfrom
proxy/1050-hotrestart-nonblocking-forward

Conversation

@bpalermo

@bpalermo bpalermo commented Sep 28, 2026 •

Copy link
Copy Markdown
Owner

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-stats workaround 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 main d0b811f):

  • Parent side. After the child's drainParentListeners(), every UDP/QUIC packet no parent session owns is posted to the parent's main thread and sent to the child over the _udp AF_UNIX datagram socket with RpcStream::sendHotRestartMessage, which flips the socket to blocking and calls sendmsg() 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-s window.
  • Child side. Every stats flush runs mergeParentStatsIfAny → getParentStats → receiveHotRestartMessage(Blocking::Yes) on the child's main thread, with no timeout, and reads nothing from the _udp socket while it waits. duplicateParentListenSocket (a listener added during the window) has the same shape.

Once the child's _udp socket queue is full, the parent's main thread is parked in sendmsg() and never reads the child's Stats request; the child's main thread is parked in recvmsg() and never drains the _udp socket. 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_VERSION unchanged, so it hot-restarts across an unpatched parent (first roll) and an unpatched child (rollback).

Parent: forwarding never blocks. HotRestartingParent::sendHotRestartMessage (the NonDispatchedUdpPacketHandler sink) 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-blocking sendmsg(MSG_DONTWAIT). EAGAIN/ENOBUFS leave 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 s ECONNREFUSED sleep-retry and the RELEASE_ASSERT are 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 through waitForParentReply(): receive in 10 ms slices (SO_RCVTIMEO), and between slices drain the _udp socket with the same onSocketEventUdpForwarding() 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):

  • no reply within 30 s, or the probe's send times out (parent not draining its socket): the parent is written off as unresponsive. No further request waits on it (stats are not merged, new listeners bind their own sockets, admin-shutdown handshake returns nullopt), the drains stay pending, and sendParentTerminateRequest still 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 existing RELEASE_ASSERTs.
  • the probe is refused (ECONNREFUSED: the parent process is gone): the parent is written off as gone: the drains complete immediately (inherited UDP listeners unpause, as sendParentTerminateRequest would do) and the stat merger is finalized.
  • drainParentListeners and sendParentTerminateRequest (no reply expected) send with allow_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 and SO_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 returns TimedOut instead of hanging, so a parent reply to a child that stopped reading is abandoned after 1 s per datagram. sendHotRestartMessage keeps its bool contract; trySendHotRestartMessage reports Sent/ConnectionRefused/TimedOut for the probe.

Not changed: the child's ECONNREFUSED sleep-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 _udp socket (that is the parent's blocked sendmsg completing). The test calls getParentStats() and asserts the packet was delivered to the worker router and the reply merged.

  • Without the patch, the child's blocking receive gets 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 old Blocking::Yes semantics restored). In production that same interleaving is the wedge rather than an abort because the real socket blocks forever instead of returning.
  • With the patch it passes, along with the companion cases: the same interleaving on a listen-socket hand-off; unresponsive after the deadline; gone on a refused probe (drains complete); unresponsive on a timed-out probe; unresponsive on a timed-out request send.

Parent side (hot_restarting_parent_test.cc, HotRestartingParentUdpForwardingTest): forwarding leaves the socket non-blocking; EAGAIN queues 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; ECONNREFUSED drops 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/server hot-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.sh with WEDGE_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 that server.hot_restart_generation still accumulates and that the child's stats merge (--skip-hot-restart-parent-stats off) 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

…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]>
@bpalermo

Copy link
Copy Markdown
Owner Author

Kind red/green (workaround off: proxy.hotRestart.skipParentStats=false, confirmed via server_info every run)

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 showed server.parent_connections 54→36→35→0 during drain, server.total_connections 108 (own + parent); parent-only downstream_cx_drain_close counters 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=1 in e2e/eastwest-quic.sh to load a locally built proxy image, and e2e/hotrestart-wedge.sh reading per-pod status files before killing the load (the load-*.txt summaries were always empty).

🤖 Generated with Claude Code

@bpalermo
bpalermo marked this pull request as ready for review September 28, 2026 20:30
@bpalermo
bpalermo merged commit c104610 into main Sep 28, 2026
25 checks passed
@bpalermo
bpalermo deleted the proxy/1050-hotrestart-nonblocking-forward branch September 28, 2026 20:31
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]>
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.

1 participant