Skip to content

hot restart: retry the terminate request and wait for the parent to exit - #48319

Closed
bpalermo wants to merge 10 commits into
envoyproxy:mainfrom
bpalermo:hot-restart-terminate-until-parent-exits
Closed

bpalermo wants to merge 10 commits into
envoyproxy:mainfrom
bpalermo:hot-restart-terminate-until-parent-exits

Conversation

@bpalermo

Copy link
Copy Markdown
Contributor

Commit Message: hot restart: retry the terminate request and wait for the parent to exit
Additional Description:

Stacked on #47834 and kept as a draft until it lands; until then this PR's diff also shows that PR's changes (this change is the top commit only). Follow-up to the review comment on #47834 about the terminate request: #47834 (comment)

At the end of the drain period HotRestartingChild::sendParentTerminateRequest() completed the drains, which unpauses the UDP listeners inherited from the parent, and then sent the terminate request once, ignoring a failure. If the parent was alive but not reading its domain socket (full, so the send timed out), it never got the request and kept running. Both processes then read the same UDP sockets: a packet of one of the parent's QUIC connections that the child dequeues is unknown to the child and gets a stateless reset. Even when the request is delivered, the child takes over the sockets while the parent's workers may still be reading them, until the parent actually exits.

Fix, in the child only:

  • The terminate request is sent as before (blocking up to the send timeout). If the parent's socket is full, the request is retried every 50 ms from a timer on the main dispatcher, with a non-blocking send, so the main thread never waits on the parent.
  • Once the request is accepted, the same timer probes the parent's socket; the drains complete when it refuses our datagrams, i.e. the parent has exited. Packets for the inherited sockets queue in the kernel meanwhile.
  • The wait is capped at 2 s. At the cap the drains complete anyway, with a warning if the parent was told but has not exited, or an error if it never accepted the request (it keeps running, and has to be stopped by other means, as before).
  • A parent that is already gone completes the drains at once, as before.

RpcStream::trySendHotRestartMessage takes an optional Blocking::No for the retries. No protocol change.

Runtime guard: envoy.reloadable_features.hot_restart_wait_for_parent_exit (default true); with it off the drains complete when the request is sent, as before.

This is not airtight: a parent that stays wedged past the cap still runs alongside the child. Envoy has no way to stop it (the child does not know the parent's PID), so that stays with whatever launches the processes; the error log says so.

Testing: HotRestartingChildTest gains DrainsCompleteOnlyAfterParentHasExited (the drained callbacks, including one registered during the wait, run only when the exit probe is refused; the probe does not block), ResendsTerminateWhileParentSocketIsFull (the request is retried without blocking until accepted, then the exit is awaited), DrainsCompleteAtTheCapIfParentLingers, DrainsCompleteAtTheCapIfTerminateIsNeverAccepted, DrainsCompleteImmediatelyIfParentIsAlreadyGone and DrainsCompleteAtOnceWhenWaitingForParentExitIsDisabled. The existing terminate tests now wait for the exit. Hot restart child, parent, base and impl tests, server_test and hotrestart_test pass.

Risk Level: low (hot restart child, end of the drain period only; runtime guarded)
Testing: unit tests (new), hot restart and server tests, hot restart integration test
Docs Changes: N/A
Release Notes: minor_behavior_changes
Platform Specific Features: N/A
Runtime guard: envoy.reloadable_features.hot_restart_wait_for_parent_exit

… other

During a hot restart the parent forwards UDP/QUIC packets it cannot
dispatch to the child over a unix datagram socket, from its main thread,
with a blocking sendmsg(). The child's main thread waits for the parent's
replies (stats merge every flush interval, listen socket hand-offs) with a
blocking recvmsg() and does not read forwarded packets while doing so.
Once the child's socket fills up, the parent blocks in sendmsg() and never
answers the child's request; both main threads then wait on each other for
good, with admin, xDS, timers and signal handling dead in both processes.

Parent: forwarded packets go through a bounded non-blocking send queue on
the UDP forwarding stream, flushed at once and retried on a short timer
while the child's socket is full. Nothing on that path blocks, sleeps or
asserts any more: a full queue drops packets, a child that is gone drops
the queue. New server.hot_restart_udp_forwarding_{datagrams,retries,dropped}
counters report it.

Child: while waiting for a parent reply it keeps servicing the UDP
forwarding socket, probes the parent for liveness and gives up after a
bounded deadline. A parent that stopped answering is written off (no more
stats merges, new listeners bind their own sockets, terminate is still
sent); a parent whose socket is gone completes the drain as terminate would.

RpcStream: the domain sockets get send/receive timeouts, a blocking receive
returns nothing after its slice instead of asserting, and a blocked send
fails after its timeout instead of hanging. The wire protocol is unchanged.

Signed-off-by: Bruno Palermo <[email protected]>
…ng-udp-forwarding

Signed-off-by: Bruno Palermo <[email protected]>

# Conflicts:
#	test/server/hot_restarting_child_test.cc
Signed-off-by: Bruno Palermo <[email protected]>
Signed-off-by: Bruno Palermo <[email protected]>
…he failure paths

waitForParentReply() measured its deadline with absl::Now(), the wall
clock; use the steady clock so a clock step cannot move it.

Add tests for the listen socket and admin shutdown requests that cannot
be sent, the admin shutdown request that gets no reply, the error log
when a forwarded packet fails while waiting, and the parent queueing
without a retry timer after shutdown().

Signed-off-by: Bruno Palermo <[email protected]>
At the end of the drain period the child completed the drains (which
unpauses the inherited UDP listeners) and then sent the terminate request
once, ignoring a failure. A parent whose socket was full never got the
request and kept running, reading the same UDP sockets as the child.

The child now retries the request from a timer, without blocking, while
the parent's socket is full, and completes the drains once the parent has
exited (its socket refuses our datagrams), capped at two seconds. At the
cap it logs, at error level if the parent never accepted the request.

Guarded by envoy.reloadable_features.hot_restart_wait_for_parent_exit.

Signed-off-by: Bruno Palermo <[email protected]>
@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: #48319 was opened by bpalermo.

see: more, trace.

@bpalermo

Copy link
Copy Markdown
Contributor Author

/retest

…s time source

With send and receive timeouts set on the domain socket, a signal
interrupts a blocking sendmsg() or recvmsg() with EINTR even for
handlers installed with SA_RESTART (signal(7)). Retry the send, and
treat an interrupted receive like the receive timeout, instead of
asserting. Measure the reply deadline with the main dispatcher's time
source, which the child already has when it first waits.

Signed-off-by: Bruno Palermo <[email protected]>
…t-terminate-until-parent-exits

Signed-off-by: Bruno Palermo <[email protected]>

# Conflicts:
#	source/server/hot_restarting_base.cc
#	source/server/hot_restarting_child.h
@bpalermo bpalermo closed this Oct 21, 2026
@bpalermo
bpalermo deleted the hot-restart-terminate-until-parent-exits branch October 26, 2026 20:42
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