Repository navigation
fix(proxy): a hot-restart child with fewer workers than its parent no longer crashes on a forwarded UDP datagram (#1126) - #1133
Merged
Conversation
…start child does not have (#1126) Adds the carried patch envoy-aether1126-forwarded-udp-worker-index.patch with its two tests only, ahead of the fix, so the proxy CI run on this commit shows them failing against the unfixed Envoy: - udp_listener_impl_test DeliverMapsAWorkerIndexItDoesNotHaveOntoItsOwnWorkers - hot_restarting_child_test ForwardsPacketFromAParentWorkerTheChildDoesNotHave Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
…does not have onto index % concurrency (#1126) The hot-restart parent forwards each UDP/QUIC datagram it cannot dispatch tagged with ITS worker index; the child delivered it with UdpListenerWorkerRouterImpl::deliver(), which indexed its per-worker table with only an ASSERT. A child with fewer workers than its parent (proxy.concurrency 4 -> 2) read past the end of the table and segfaulted. deliver() now maps an index this instance does not have onto index % workers, which for a parent count that is a multiple of the child's is the worker the child's own connection-ID routing picks. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
…udp-worker-index # Conflicts: # docs/runbook.md
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.
Closes #1126
What crashed
On 2026-10-01 the rollout that changed the node proxy from 4 Envoy workers to 2 (
proxy.concurrency: 2) segfaulted the 2-worker hot-restart successor inHotRestartingChild::onForwardedUdpPacketon 4 of 5 nodes. The reverse change (2→4) did not crash.Root cause
Line numbers are for the Envoy source this image builds: pin
726d7acwith the carried patches applied (bazel/patches/, through aether1074).HotRestartingParent::Internal::drainListeners,source/server/hot_restarting_parent.cc:289-293), a QUIC listener hands every packet it cannot dispatch to the hot-restart forwarder along with itsworker_index_(source/common/quic/active_quic_listener.cc:198-203). A raw UDP listener does the same (source/server/active_udp_listener.cc:125-130).Internal::handlewrites that index into the message (hot_restarting_parent.cc:102). A 4-worker parent sends indices 0–3.onSocketEventUdpForwardingpassesreq.worker_index()straight through (source/server/hot_restarting_child.cc:477).onForwardedUdpPacketcallslistenerWorkerRouter(addr).deliver(worker_index, …)(hot_restarting_child.cc:141). Its own comment (:125-140) already says forwarding "will fail" if the worker count changes.UdpListenerWorkerRouterImpl::deliver(source/common/network/udp_listener_impl.cc:200-212) guards the index with anASSERTonly, and that is compiled out of release builds. It then readsworkers_[dest_worker_index]from astd::vectorsized to the child's concurrency (2).workers_[i]reads heap memory past the end of a 16-byte vector buffer. That garbage is used as aUdpListenerCallbacks*, andworker->post(std::move(data))(udp_listener_impl.cc:210) makes a virtual call through it: SIGSEGV. When the garbage word happens to be zero, the datagram is silently dropped instead, which is why the crash was intermittent per node. The proxy CI run on this PR's first commit (tests only, no fix) reproduced exactly this:udp_listener_impl_test … terminated by SIGSEGV(see Test evidence below).What
Mismatched worker index. expected 3, actual 1isIt is a parent-side diagnostic, not the child's bounds check.
ActiveQuicListener::destination(active_quic_listener.cc:260-270) logs it when kernel BPF routing delivered a packet to a worker other than the one its own selector picks, and then keeps the packet where it is. The QUIC worker selector does not encode a worker id. It computes the first 4 connection-ID bytes% concurrency, both in the CBPF program (source/common/quic/envoy_deterministic_connection_id_generator.cc:82,mod #socket_count) and inbpfEquivalentFunction(:129). The child applies its listener socket options atSTATE_BOUNDto the duplicated parent sockets too (source/common/listener_manager/listener_impl.cc:187). Those options includeSO_ATTACH_REUSEPORT_CBPFbuilt with the child's concurrency (active_quic_listener.cc:415-420). A reuseport BPF program belongs to the whole socket group, so the child replaces the parent'smod 4steering withmod 2. From then on the parent's workers 0 and 1 receive every packet. A connection whose CID % 4 = 3 (or 2) arrives at worker 3 % 2 = 1 (or 0). That is precisely the logged pairsexpected 3, actual 1andexpected 2, actual 0. The log is a symptom of the count change, not the crash site. The out-of-range index itself comes from parent workers 2 and 3 forwarding whatever they still read after the drain starts. That is either datagrams already queued on their sockets, or a listener whose child-side socket (and so the BPF re-attach) only appears after the drain began.Neighbouring paths (same out-of-range assumption?)
getListenSocketsForChildonly returns a socket forworker_index < parent concurrency(hot_restarting_parent.cc:220), and fd-1otherwise. On a 2→4 change the child binds freshSO_REUSEPORTsockets for workers 2 and 3 (listener_manager_impl.cc:375-390, fallback below). On a 4→2 change the child never asks for 2 and 3. The parent closes its unshared TCP sockets when its listeners stop (maybeCloseSocketsForListener,listener_manager_impl.cc:1386-1393), and connections already in those accept queues are reset (notcp_migrate_req). That costs a few connections once, which is what the chart comment already warns about. It does not crash.maybeCloseSocketsForListenerskips UDP. Under the child'smod 2program they receive no new datagrams. Datagrams still queued when the parent exits are lost (UDP: dropped, not reset).ActiveUdpListenerBase::onDataasserts that its owndestination()is below its concurrency (active_udp_listener.cc:67). Only the hot-restart forwarder can handdeliver()a foreign index.The patch:
proxy/bazel/patches/envoy-aether1126-forwarded-udp-worker-index.patchIt is applied after aether1074, and it is child-side only, so it takes effect from the first roll onto an image built from it.
UdpListenerWorkerRouterImpl::deliverno longer reads past its table. An index this instance does not have is mapped ontoindex % workers, with a power-of-two rate-limitedinfolog (udp worker index N is not one of this instance's M workers …). An in-range index behaves exactly as before, including the existing "no worker registered → drop" case. TheUdpListenerWorkerRouter::deliverdoc comment (envoy/network/listener.h) and the stale comment inonForwardedUdpPacketare updated. The patch is oneifblock, with no interface or mock changes. It covers QUIC and raw UDP (udp_proxy) alike, because both forward through the same router.Why remap rather than drop. The forwarded datagrams are exactly the ones the parent could not dispatch: new handshakes, and packets of connections the child already accepted from a forwarded handshake. For the child to keep such a connection, the session has to sit on the worker the kernel will send its later packets to once the parent is gone. That worker is CID % child_concurrency. The parent's index for a packet it received through its own BPF is CID % parent_concurrency, and
(CID % 4) % 2 == CID % 2. So when the parent's count is a multiple of the child's (4→2, 8→4, 4→1, …),index % concurrencyis exactly the child's own connection-ID routing, and such connections survive the count change. For other counts (for example 3→2) it is merely safe: the datagram lands on a valid worker, and a connection set up that way may later be reset, as a dropped packet would have caused anyway. The general fix (re-run the child's CID selector on the forwarded packet) needs a new method onUdpListenerCallbacksplus mocks, so it is left to upstream.Test evidence (red, then green)
Two tests are added to targets that
//bazel/patches:carried_patch_testsalready runs, and so the proxy CI job'sbazel test //...runs them too:@envoy//test/common/network:udp_listener_impl_testUdpListenerWorkerRouterImplTest.DeliverMapsAWorkerIndexItDoesNotHaveOntoItsOwnWorkers: a real 2-worker router. Indices 0 and 1 are delivered as addressed, a 4-worker parent's indices 2 and 3 land on workers 0 and 1, and a mapped index with no registered worker is dropped.@envoy//test/server:hot_restarting_child_testHotRestartingChildTest.ForwardsPacketFromAParentWorkerTheChildDoesNotHave: the forwardedHotRestartMessageof a 4-worker parent's worker 3 reaches a 2-worker child's real router and is posted to worker 1.Red: commit
5dc33be(the patch with only the test hunks), proxy CI amd64 leg:Testing @@envoy+//test/common/network:udp_listener_impl_test failed: (Exit 34): … command was terminated by SIGSEGV. That is the production crash, in the release-mode (ASSERT-less) build.Green: commit
928e45c(the fix), proxy CI run 37044395786: amd64 and arm64 legs both pass,Executed 14 out of 14 tests: 14 tests pass.(//..., which includes//bazel/patches:carried_patch_testsand so both new tests; the red run had stopped at10 tests pass and 4 were skipped).Local build: I started
bazel test @envoy//test/common/network:udp_listener_impl_test @envoy//test/server:hot_restarting_child_testinproxy/, but did not finish it. The workstation was at load average around 240 with several other Envoy builds running, and the run sat compiling test mocks for over an hour before it was stopped. The proxy CI job, which runs on BuildBuddy RBE, is the evidence here. Root workspace:bazel test //charts/...passes (53/53).Docs
charts/aether/values.yaml(proxy.concurrency),docs/configuration.mdand runbook § Sizing nodes for a proxy hot restart: the crash is fixed by this patch in proxy images built from it or later, and the supervisor: the old pod's self-drain calls the Envoy admin on 127.0.0.1:9901 without checking it is its own Envoy — it drained the NEW pod's freshly started Envoy, which then served no new listeners #1127 supervisor fix is the other prerequisite.proxy/MODULE.bazelcomment,proxy/README.md"Carried today",proxy/bazel/patches/BUILD.bazelcomment.2.2.0→2.2.1.Is a concurrency change now safe for existing QUIC connections?
Not fully. The crash is fixed; connection survival is not guaranteed in either direction. This is an inference from the code, not measured.
mod 2program. A connection whose CID % 4 ≠ CID % 2 (about half of them) has its packets steered to a parent worker that does not own it. Before the drain, quiche answers with a stateless reset. After the drain, the packet is forwarded to the child, which does not know the connection either. That is theMismatched worker indextraffic. Handshakes accepted by the child during the drain survive, thanks to the remap.parentDrainedCallbackRegistrar,listener_manager_impl.cc:388). Under the child'smod 4program, about half of the parent's existing QUIC connections (CID % 4 ∈ {2,3}) are steered to those sockets, and the child, which does not know them, would stateless-reset them. Separately, a handshake forwarded from parent workerilands on child workeri(CID % 2), not on CID % 4.So a
proxy.concurrencychange remains a one-time event that costs a share of the live QUIC connections (h3 clients reconnect) and a few queued TCP connections. Same-count restarts are unaffected.Follow-up (not in this PR; the supervisor is #1127's area)
A supervisor-side guard: when the next epoch's
--concurrencydiffers from the live parent's, do not HOT restart. Do a drain-then-fresh-start instead, or at least log it loudly. That would remove the QUIC share above as well. It is out of scope here: this PR changes no supervisor or Go code. (#1127, merged as #1134 while this PR was open, fixed the self-drain inagent/internal/proxy/hotrestart; it does not add this guard.)The same bug very likely exists upstream.
onForwardedUdpPacket→UdpListenerWorkerRouterImpl::deliverwith the parent's index, guarded only by anASSERT, is in the envoyproxy/envoy#47743 forwarding code (merged 2026-09-30) and in the original hot-restart UDP forwarding it extends. A hot restart that lowers--concurrencywhile QUIC/UDP listeners forward is undefined behaviour in release builds. The child re-attaching the reuseport CBPF program group-wide (listener_impl.cc:187) during the handoff, which moves the parent's steering, is a related upstream behaviour worth raising in the same report. Reporting it is the maintainer's call.🤖 Generated with Claude Code
https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr