Skip to content

fix(worker): event-loop fixes for soft stop, accept, listener orders, health and UDP - #1931

Merged
FlorentinDUBOIS merged 11 commits into
mainfrom
fix/worker-event-loop
Nov 20, 2026
Merged

FlorentinDUBOIS merged 11 commits into
mainfrom
fix/worker-event-loop

Conversation

@FlorentinDUBOIS

@FlorentinDUBOIS FlorentinDUBOIS commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Fourteen defects in the worker's event loop, its listeners, its health-check bookkeeping and its UDP listener session, in nine fix commits; each carries its tests and its CHANGELOG.md entry (Unreleased, Fixed). Two further commits repair test recipes.

A RemoveListener could stall a worker's soft stop for good (accounting drift). The RemoveListener arm of Server::notify_proxys lowered base_sessions_count before checking that a listener slot was released, so the soft-stop exit test could never hold again and sozu upgrade --worker waited forever. The count now falls only where a slot is released.

A response larger than max_command_buffer_size froze the worker (stuck state). Server::send_queue retried a frame the channel refuses for good, forever, so the worker's only thread never returned to epoll_wait; an unfiltered QueryMetrics could freeze the whole fleet. The response is now dropped and a terminal answer replaced by a short Failure for the same request id.

A removed HTTP, HTTPS or TCP listener kept its socket open while sessions held it (resource leak). Sessions hold an Rc to the listener that owns the socket, so it stayed listening under a freed token. The proxies now take the socket out and deregister it before dropping the entry.

UDP drops were counted twice, and a send error met while draining a queue not at all (accounting drift). Each core-side drop was recorded from both its metric event and its Output::Drop; WriteQueue::drain dropped on a hard send error without counting udp.datagrams.dropped.send_error. Both are now counted once.

UDP replies stranded behind a pending ICMP error, and a return path lost after a hand-off (stuck state). The edge-triggered upstream drain stopped at the first hard recv error, ahead of queued replies; it now reads on, bounded to eight consecutive errors. A client-return queue kept across a socket hand-off swallowed every later reply; the hand-off now discards it and counts its datagrams.

The accept gate could close for good (stuck state). SessionManager::decr was the only code that reopened can_accept, below max_connections * 90 / 100, which is 0 for max_connections = 1; a gate closed by the slab test or a dry TCP pool with no session counted had nothing left to reopen it. The threshold is now never below one session, and every loop turn reopens a gate with no counted session when check_limits would admit a connection.

A failed accept(2) stranded the connections already queued (stuck state). The Err arm of Server::accept dropped the edge-triggered listener from accept_ready on EMFILE, ENFILE or ECONNABORTED. The listener now stays armed and is retried after 250 ms; one with no socket left is dropped through a new AcceptError::NoListenSocket.

A socket queued for a removed listener was served by the listener that reused its token (race replay). RemoveListener left the listener's sockets in accept_queue, which names listeners by token, and the slab hands the freed token to the next AddListener. The removal now closes the sockets queued for the token it releases.

Aborting a cluster's first protected health check left its backends DOWN (teardown loss). The abort dropped the configuration but kept the DOWN marks and the probes in flight, with no prober left to mark the backends UP. It now resets the cluster's backends and drops its probes, as RemoveHealthCheck does.

A UDP activation whose session could not be built left the listener half-active (teardown loss). The socket stayed bound and registered with no session to read it while the control plane believed the listener inactive. The activation is now taken back as a whole by UdpProxy::abandon_activation.

A draining worker activated listeners ordered after its soft stop (invalid transition). The soft stop had emptied the listener maps, so a later AddListener and ActivateListener bound a fresh SO_REUSEPORT socket whose connections the same turn closed. Server::notify_activate_listener now refuses while the worker shuts down, before anything is bound.

An AddCluster for a UDP cluster reset the health its UDP prober had recorded (invalid transition). A UDP cluster carries no health_check, so each upsert reset every backend to healthy although the prober keeps running. Server::add_cluster now records whether a UDP prober is armed (BackendMap::set_udp_health_prober), and BackendMap::reset_cluster_health leaves such a cluster's health to the prober.

Behaviour changes

  • udp.datagrams.dropped and the core-side reason counters read half their previous rate; send_error and unknown_flow now also count the drain and hand-off cases.
  • A terminal worker answer larger than max_command_buffer_size reaches the main process as a Failure for that request id.
  • RemoveListener closes an activated listener's socket at once, and closes the client connections still queued for it.
  • A listener whose accept(2) keeps failing is retried for the worker's lifetime, at most about four times a second, each retry logging an error. AcceptError gains a NoListenSocket variant (library API).
  • Aborting the first protected health check of a cluster resets its backends to healthy, cluster-wide.
  • A failed UDP activation leaves the listener inactive; a socket the worker bound is closed, an inherited one kept parked.
  • ActivateListener on a draining worker is answered with a failure naming the address.
  • A UDP cluster with an armed udp.health prober keeps its backends' health across AddCluster, RemoveHealthCheck and the abort of a protected change.

Tests added

  • server::listener_lifecycle_tests: removing_an_unknown_listener_leaves_base_sessions_count_unchanged, a_remove_listener_after_a_soft_stop_does_not_stall_the_drain, removing_an_activated_tcp_listener_closes_its_socket_while_a_session_holds_it, removing_an_activated_http_listener_closes_its_socket_while_a_session_holds_it, removing_an_activated_https_listener_closes_its_socket_while_a_session_holds_it, a_socket_queued_for_a_removed_listener_is_not_served_by_the_listener_that_reuses_its_token, a_udp_activation_whose_session_cannot_be_built_leaves_no_active_listener, a_udp_activation_without_a_session_slot_is_taken_back_and_can_be_retried, a_listener_ordered_after_a_soft_stop_is_not_brought_back, a_refused_activation_after_a_soft_stop_names_the_address_and_keeps_the_drain_finishable
  • server::send_queue_tests: a_response_larger_than_the_channel_ceiling_does_not_wedge_send_queue, an_oversized_response_is_answered_with_a_failure_for_the_same_request, an_oversized_progress_response_is_dropped_without_a_stand_in, a_ceiling_too_small_for_the_failure_drops_it_instead_of_looping
  • server::tests: the_accept_gate_reopens_when_the_only_session_of_a_one_connection_cap_closes, a_stranded_gate_reopens_but_one_a_counted_session_can_still_reopen_does_not
  • server::accept_ready_tests: a_gate_closed_by_the_slab_reopens_once_the_slab_shrinks_with_no_session_left, a_failed_accept_does_not_strand_the_connections_queued_behind_it, the_retry_pause_holds_the_deferred_accept_pass_until_it_elapses, a_listener_with_no_socket_is_not_retried_after_a_failed_accept
  • server::initial_protected_bootstrap_tests: aborting_the_first_protected_health_check_resets_a_backend_its_probes_marked_down, aborting_the_first_protected_health_check_drops_its_probes_in_flight
  • server::remove_health_check_tests: add_cluster_of_a_udp_cluster_with_udp_health_keeps_a_backend_marked_down, remove_health_check_of_a_udp_cluster_with_udp_health_keeps_a_backend_marked_down, add_cluster_of_a_udp_cluster_with_health_off_resets_a_backend_marked_down
  • backends::backends_test: a_udp_prober_keeps_its_verdict_when_the_health_check_goes_away
  • udp::tests: a_core_side_dropped_datagram_is_counted_once, a_hard_error_draining_the_upstream_queue_is_counted_as_send_error, a_hard_error_draining_the_client_queue_is_counted_as_send_error, a_pending_icmp_error_does_not_strand_the_replies_queued_behind_it, a_client_return_queue_kept_across_a_handoff_is_drained_after_reactivation, a_handoff_counts_the_client_return_datagrams_it_discards
  • udp::activation_abandon_tests: abandoning_an_activation_closes_the_socket_the_listener_bound, abandoning_an_activation_keeps_the_inherited_socket_and_what_it_queued

Each proving test fails without its fix and passes with it. Six tests had a TO SEE THIS RED recipe that named no statement to change ("nothing to change, it is red on the unfixed tree"); the two recipe commits replace each with the mutation of the fixed code that turns it red, and every one of those mutations was applied and seen failing on the test's own assertion.

Validation

Run locally on the final tree with the pinned toolchain (Rust 1.93.1, rustfmt from nightly):

  • cargo +nightly fmt --all -- --check: exit 0, no output.
  • cargo clippy --all-targets --locked -- -D warnings: exit 0, Finished dev profile.
  • cargo clippy --all-targets --locked --features opentelemetry,splice,simd -- -D warnings: exit 0, Finished dev profile.
  • cargo clippy --all-targets --release --locked --features opentelemetry,splice,simd -- -D warnings: exit 0, Finished release profile.
  • RUSTDOCFLAGS='-D warnings' cargo doc --no-deps --locked --features opentelemetry,splice,simd: exit 0.
  • cargo test --workspace --locked --no-fail-fast -- --skip tests::fuzz_tests::: exit 0. sozu-lib 1764 passed; 0 failed, sozu lib and bin 273 passed; 0 failed each, sozu-command-lib 416 passed; 0 failed, sozu-e2e 693 passed; 0 failed, every integration and doc-test target ok.
  • The nine process-level suites of the CI step "Test sozu (process-level e2e)", each cargo test -p sozu --locked --test <suite> -- --ignored: all ok.
  • Test hygiene (no bare #[ignore]): ok.
  • python3 .github/scripts/check_doc_citations.py --base c6098095d3a2c1738a90cfbc17865f718d648276, with the self-test and the broken-fixture check: exit 0, every rule OK.

Not run

  • The simulations (RUSTFLAGS='--cfg tokio_unstable' cargo test -p sozu-sim): udp_simulation drives the sans-io UdpManager, whose only change here is doc comments, and no simulation reaches the listener, accept, health-state or UDP-session code changed here.
  • The CI proc-observer-e2e suites, which need a user-namespace observer of /proc; the --all-features clippy and documentation builds; the crypto-provider cells (aws-lc-rs, openssl, fips); fuzzing, the dependency advisory scan and the real protocol services.

@FlorentinDUBOIS
FlorentinDUBOIS marked this pull request as ready for review November 19, 2026 20:04
@FlorentinDUBOIS FlorentinDUBOIS changed the title fix(worker): event-loop fixes for soft stop, oversized responses, listener removal and UDP fix(worker): event-loop fixes for soft stop, accept, listener orders, health and UDP Nov 20, 2026
@FlorentinDUBOIS
FlorentinDUBOIS enabled auto-merge (rebase) November 20, 2026 08:18
…reed

The `RemoveListener` arm of `Server::notify_proxys` decremented
`base_sessions_count`, the number of slab slots that are not client
sessions, before it asked the proxy for the listener's slab token, and
the slab slot is freed only when that token is found. When the proxy
did not hold the address, nothing was released and the count fell under
the slots still in the slab, so the soft-stop exit test
(`slab.len() <= base_sessions_count`) could never hold again and the
worker never answered its `SoftStop`. `sozu upgrade --worker` waits for
that answer with no timeout.

Two cases led there: a draining worker, whose proxies a soft stop had
already emptied of listeners and which an untargeted scatter still
reaches, and a worker that refused an `AddListener` because its session
list was full while another worker accepted it and the main process
kept the listener. A `RemoveListener` for an unknown address also
tripped the `debug_assert!` in debug builds, and enough of them could
wrap the count in release builds.

The decrement now sits inside `if let Some(token) = listen_token`, next
to `slab.try_remove(token.0)`, so the count falls only where a listener
slot is released; the `debug_assert!` moved with it. The response sent
to the main process is unchanged. `doc/lifetime_of_a_session.md`
explains the exit test and the `RemoveListener` rule.

Tests (server::listener_lifecycle_tests):
- removing_an_unknown_listener_leaves_base_sessions_count_unchanged
- a_remove_listener_after_a_soft_stop_does_not_stall_the_drain

Signed-off-by: Florentin Dubois <[email protected]>
… good

`Channel::write_delimited_message` refuses a frame larger than
`max_buffer_size` with `MessageTooLarge` before buffering a byte, and
with an empty back buffer that refusal can never lift. `Server::send_queue`
pushed every refused response back to the head of its queue and looped:
nothing drained, `readiness` stayed WRITABLE, and the worker's only
thread never returned to `epoll_wait`, so it served no traffic and
answered nothing. An unfiltered `QueryMetrics` (what `sozu top` sends) on
a worker with many clusters and backends, or a lowered
`max_command_buffer_size`, is enough, and the query is scattered to every
worker, so the whole fleet froze together.

`send_queue` now hands a permanent refusal (`MessageTooLarge` with a
message longer than the ceiling, the mirror of `is_transient_overflow`
on the main-process side) to a new `refuse_oversized_response`, which
logs it and drops the response. A dropped terminal answer (`Ok` or
`Failure`) is replaced by a short `Failure` for the same request id that
names `max_command_buffer_size`, which the supervisor counts as that
worker's failed answer; the stand-in is re-queued only on a transient
refusal and dropped otherwise, so it cannot loop either. An oversized
`Processing` report or event is dropped with the log alone. A transient
refusal, and every other error, keep the previous `push_front`.
`doc/configure_admin_ops.md` documents the ceiling's new behaviour.

To drive `send_queue` from tests, `bare_server` gains a sibling
`bare_server_with_command_channel(buffer_size, max_buffer_size)` that
hands back the main process's end of the channel; `bare_server` behaves
as before.

Tests (server::send_queue_tests):
- a_response_larger_than_the_channel_ceiling_does_not_wedge_send_queue
- an_oversized_response_is_answered_with_a_failure_for_the_same_request
- an_oversized_progress_response_is_dropped_without_a_stand_in
- a_ceiling_too_small_for_the_failure_drops_it_instead_of_looping

Signed-off-by: Florentin Dubois <[email protected]>
… hold it

On `RemoveListener`, `HttpProxy::remove_listener`,
`HttpsProxy::remove_listener` and `TcpProxy::remove_listener` only
dropped the proxy's map entry. Every session accepted on the listener
clones its `Rc<RefCell<…Listener>>`, and the listening socket is a
field of that object, so the socket stayed open, listening and
registered in epoll under the slab token the `RemoveListener` arm of
`Server::notify_proxys` had just freed, until the last session of that
listener closed, which an HTTP/2, WebSocket or TCP pipe session can
postpone indefinitely. The kernel kept completing handshakes into a
backlog nobody accepted, and after a re-add on the same address (the
documented way to change a TCP listener's `--sni-preread-*` options) the
orphan stayed in the new socket's `SO_REUSEPORT` group and could take a
share of its connections.

Before the existing `retain`, each proxy's `remove_listener` now calls a
new private `close_sockets(&Registry)` on every listener the same
predicate matches. It sets `active = false`, drops a socket parked by a
failed registration, then takes the socket out of the listener and
deregisters it, logging a failed deregister: the take-then-deregister
the deactivate, stop and upgrade paths already use. Sessions already
accepted keep their own sockets and run to their end, and the removal
still answers `Ok`. `doc/lifetime_of_a_session.md` states the new
behaviour.

Tests (server::listener_lifecycle_tests):
- removing_an_activated_tcp_listener_closes_its_socket_while_a_session_holds_it
- removing_an_activated_http_listener_closes_its_socket_while_a_session_holds_it
- removing_an_activated_https_listener_closes_its_socket_while_a_session_holds_it

Signed-off-by: Florentin Dubois <[email protected]>
…raining

Two counting defects in the UDP listener session.

`UdpManager::drop_datagram` announces each drop the core decides as both
`Output::Metric(MetricEvent::DatagramDropped(reason))` and
`Output::Drop(reason)`, and `UdpListenerSession::drain_outputs` routed
both to `record_drop`, so `udp.datagrams.dropped` and the reason
counters (`invalid`, `truncated`, `no_backend`, `shed`, `unknown_flow`)
moved by two per dropped datagram. The `Output::Drop(_)` arm no longer
counts, so `record_metric` is the only caller of `record_drop`; the core
still emits `Output::Drop`, which its own tests observe, and its
`manager.rs` and `mod.rs` changes are doc comments only. Dashboards and
alerts on these counters see them halve on upgrade.

`WriteQueue::drain` popped a queued datagram whose send returned
`SendOutcome::Dropped` and moved no counter, although the immediate send
paths count the same error as `udp.datagrams.dropped.send_error` and
`SendOutcome::Dropped` is documented as counted. A backend refusing
traffic under load therefore looked healthier than it was. The count is
now made once, in the `Dropped` arm of `WriteQueue::drain`, which the
per-flow upstream queue and the listener's client-return queue share;
the two drain closures stay count-free. The UDP `LIFECYCLE.md` and the
`SendOutcome`, `WriteQueue::drain`, `Output::Drop` and
`MetricEvent::DatagramDropped` docs say where each count happens.

Tests (udp::tests):
- a_core_side_dropped_datagram_is_counted_once
- a_hard_error_draining_the_upstream_queue_is_counted_as_send_error
- a_hard_error_draining_the_client_queue_is_counted_as_send_error

Signed-off-by: Florentin Dubois <[email protected]>
Two ways the UDP listener session stopped delivering replies.

A connected UDP socket keeps a pending ICMP error (a port-unreachable
from a restarting backend, or a middlebox that rejects one datagram of
a pipelined flow) until a `send` or a `recv` consumes it, and on Linux
the next `recv` returns that error ahead of the datagrams already
queued. `UdpListenerSession::ingest_upstream` broke out of its drain on
the first hard `recv` error, and the socket is edge-triggered, so the
queued reply stayed unread until another datagram reached the same
upstream socket, and was lost if the flow closed first. The drain now
logs the error and reads on to `WouldBlock`. A run of
`UPSTREAM_RECV_ERROR_BUDGET` (8) consecutive errors still ends it, and a
successful `recv` resets the count, so an error that never clears
cannot spin the worker. `ingest_client` keeps its break: an unconnected
socket is never handed a pending ICMP error.

`UdpProxy::give_back_listeners` takes the listener socket but kept the
session and its client-return `WriteQueue`. The WRITABLE interest that
queue waited on belonged to the socket that left, and `ActivateListener`
registers the fresh socket readable only, so after the worker was
activated again a single datagram left in the queue diverted every later
reply into it, nothing drained it, and replies were dropped as
`udp.datagrams.dropped.wq_full` once it was full. `give_back_listeners`
now calls a new `UdpListenerSession::discard_client_queue` for each
listener whose socket it hands over, which empties the queue through
`WriteQueue::discard` and counts each datagram once in
`udp.datagrams.dropped.unknown_flow`, the counter the egress path
already uses when its socket is gone. Flows and the session stay
installed, and the caller still deregisters the socket.

The UDP `LIFECYCLE.md`, `doc/lifetime_of_a_session.md` and the
`unknown_flow` counter's doc describe both changes.

Tests (udp::tests):
- a_pending_icmp_error_does_not_strand_the_replies_queued_behind_it
- a_client_return_queue_kept_across_a_handoff_is_drained_after_reactivation
- a_handoff_counts_the_client_return_datagrams_it_discards

Signed-off-by: Florentin Dubois <[email protected]>
Three tests of server::listener_lifecycle_tests and server::send_queue_tests
carried a recipe that named no statement to mutate ("nothing to change, it
is red on the unfixed tree"). Each now names the statement to change in the
fixed code and the failure it produces:

- removing_an_unknown_listener_leaves_base_sessions_count_unchanged
- a_remove_listener_after_a_soft_stop_does_not_stall_the_drain
  (move `base_sessions_count -= 1` out of the `if let Some(token)` block
  of the `RemoveListener` arm of `Server::notify_proxys`)
- a_response_larger_than_the_channel_ceiling_does_not_wedge_send_queue
  (put `queue.push_front(resp)` back in place of the call to
  `refuse_oversized_response` in `Server::send_queue`)

Each mutation was applied and the test seen failing on its own assertion
or panic, then the code was restored. Comments only.

Signed-off-by: Florentin Dubois <[email protected]>
… armed

Two ways a worker stopped accepting on its HTTP, HTTPS and TCP
listeners.

`SessionManager::decr` was the only code that set `can_accept` back to
`true`, and only below `max_connections * 90 / 100`. With
`max_connections = 1` that threshold is 0, which a count never goes
below, so the gate closed at the cap stayed closed after the one session
ended. The same happened when the slab test closed the gate on entries
that are not counted sessions (UDP flows take a slab slot without
consulting it), or the TCP buffer pool ran dry while no session was
counted: with none left to close, nothing reopened it. The reopening
threshold is now never below one session, and every turn of the event
loop reopens a closed gate when no session is counted and
`check_limits` would admit a connection. With a counted session alive
the backpressure is unchanged.

The `Err(other)` arm of `Server::accept` dropped the listener from
`accept_ready` on any accept error other than `WouldBlock` (`EMFILE`,
`ENFILE`, `ECONNABORTED`). The listener is edge-triggered, so the
connections the kernel had already completed got no further event and
waited, on a quiet listener for good. The listener now stays armed and
is retried by a later turn, no sooner than 250 ms after the failure, so
a lasting failure costs a few `accept4(2)` calls and error lines per
second and never spins the loop. A listener with no socket left
(deactivated, stopped, handed back for an upgrade) is still dropped,
through a new `AcceptError::NoListenSocket` that the HTTP, HTTPS and
TCP proxies return instead of `AcceptError::IoError`; code that matches
`AcceptError` exhaustively gains a variant to handle.
`doc/lifetime_of_a_session.md` describes both rules.

Tests:
- server::tests::the_accept_gate_reopens_when_the_only_session_of_a_one_connection_cap_closes
- server::tests::a_stranded_gate_reopens_but_one_a_counted_session_can_still_reopen_does_not
- server::accept_ready_tests::a_gate_closed_by_the_slab_reopens_once_the_slab_shrinks_with_no_session_left
- server::accept_ready_tests::a_failed_accept_does_not_strand_the_connections_queued_behind_it
- server::accept_ready_tests::the_retry_pause_holds_the_deferred_accept_pass_until_it_elapses
- server::accept_ready_tests::a_listener_with_no_socket_is_not_retried_after_a_failed_accept

Signed-off-by: Florentin Dubois <[email protected]>
…eleases

`Server::accept_queue` names the listener of each accepted socket by its
listen token only, and `create_sessions` resolves that token in the
protocol's current listener map when it pops the entry. `RemoveListener`
freed the token's slab slot and purged `accept_ready`, but left the
listener's sockets in the queue, and the slab hands the freed key to the
next `AddListener`. A socket still queued when the removal ran (its
readiness event came before the command in one `epoll_wait` result, or
`create_sessions` stopped early and left it waiting up to
`accept_queue_timeout`) therefore became a session configured by, and
routed through, a listener the client never connected to.

The `RemoveListener` arm of `Server::notify_proxys` now runs
`accept_queue.retain` on the released token, in the block that frees the
slot and purges `accept_ready`; dropping each purged entry's `TcpStream`
closes the client connection. Sockets queued for other listeners are
kept. `doc/lifetime_of_a_session.md` and `doc/debugging_strategies.md`
describe the queue's rule.

Test (server::listener_lifecycle_tests):
- a_socket_queued_for_a_removed_listener_is_not_served_by_the_listener_that_reuses_its_token

Signed-off-by: Florentin Dubois <[email protected]>
…activation

Two operations that failed halfway and left state behind.

A protected commit that installs a health check on a cluster that had
none starts probing in the same loop turn. When that commit was then
aborted, `ProtectedWorker::abort` went through
`BackendMap::restore_health_check(cluster, None, None)`, which dropped
the configuration and the protected header values but kept every DOWN
mark the aborted probes had written, and kept the probes still in
flight. The cluster then had no prober, so a backend marked DOWN stayed
out of rotation until an operator acted, although the abort is
documented to restore the state that preceded the change. The abort now
resets the cluster's backends to healthy and drops its probes in flight,
as `RemoveHealthCheck` does; an abort that restores a previous health
check is unchanged.

The UDP arm of `Server::notify_activate_listener` let
`UdpProxy::activate_listener` bind or adopt the socket, register it and
set `active = true`, and only then built the listener session. When
that failed (`Registry::try_clone` answers `EMFILE` once the worker is
out of descriptors) it answered a failure and undid nothing: the socket
stayed bound and registered with no session to read it and, with
`SO_REUSEPORT`, took a share of the address's datagrams, while the
control plane believed the listener inactive. The activation is now
taken back as a whole by `UdpProxy::abandon_activation`: the listener is
inactive again and its socket deregistered; a socket the worker bound is
closed so a retried `ActivateListener` binds again, and a socket
inherited at an upgrade is kept parked, as a failed registration already
keeps it. `doc/health_checks.md`, `doc/lifetime_of_a_session.md` and the
UDP `LIFECYCLE.md` describe both changes.

Tests:
- server::initial_protected_bootstrap_tests::aborting_the_first_protected_health_check_resets_a_backend_its_probes_marked_down
- server::initial_protected_bootstrap_tests::aborting_the_first_protected_health_check_drops_its_probes_in_flight
- server::listener_lifecycle_tests::a_udp_activation_whose_session_cannot_be_built_leaves_no_active_listener
- server::listener_lifecycle_tests::a_udp_activation_without_a_session_slot_is_taken_back_and_can_be_retried
- udp::activation_abandon_tests::abandoning_an_activation_closes_the_socket_the_listener_bound
- udp::activation_abandon_tests::abandoning_an_activation_keeps_the_inherited_socket_and_what_it_queued

Signed-off-by: Florentin Dubois <[email protected]>
…er health

Two orders a worker applied although its state said otherwise.

After a `SoftStop`, nothing in the worker refused listener orders, and
the soft stop had emptied every proxy's listener map. The main process
scatters listener orders to a `Stopping` worker like to the others, so
an `AddListener` for a new address followed by `ActivateListener` bound
a fresh `SO_REUSEPORT` socket on the draining worker: the kernel handed
it a share of the address's new connections, and the same turn's
`Server::shut_down_sessions` closed each one before a byte was read.
`Server::notify_activate_listener` now answers a failure ("the worker is
shutting down and takes no new listener") while `shutting_down` is set,
before any socket is bound or taken from the SCM table. `ActivateListener`
reaches no proxy's `notify`, so this one guard covers the HTTP, HTTPS,
TCP and UDP paths. The refusal goes through the existing
`finish_proxy_order` rollback, and the listener's slab slot is still
counted, so the drain ends as before.

A UDP cluster carries no `health_check`, its health lives in
`udp.health`, so every `AddCluster` it received (a reload that changes
it, for example) ran `set_health_check_config(cluster, None)`, which
reset each backend to healthy with zeroed counters on the premise that
nothing probes the cluster any more. The UDP prober keeps running across
the upsert and writes the same backend health, so a backend it had
marked DOWN went back into rotation without a successful probe. The
"armed UDP prober" predicate moves out of `UdpProxy::apply_cluster` into
one shared `udp_health_settings`; `Server::add_cluster` records its
answer with the new `BackendMap::set_udp_health_prober` before it sets
or clears the health check, and `BackendMap::reset_cluster_health` then
leaves such a cluster's health to the prober. The same holds for
`RemoveHealthCheck` on that cluster and for the abort of a protected
health check change. A cluster with no `udp.health`, or with
`HEALTH_OFF`, is reset as before. `doc/configure.md`,
`doc/health_checks.md`, `doc/lifetime_of_a_session.md` and the UDP
`LIFECYCLE.md` describe both rules.

Tests:
- server::listener_lifecycle_tests::a_listener_ordered_after_a_soft_stop_is_not_brought_back
- server::listener_lifecycle_tests::a_refused_activation_after_a_soft_stop_names_the_address_and_keeps_the_drain_finishable
- server::remove_health_check_tests::add_cluster_of_a_udp_cluster_with_udp_health_keeps_a_backend_marked_down
- server::remove_health_check_tests::remove_health_check_of_a_udp_cluster_with_udp_health_keeps_a_backend_marked_down
- server::remove_health_check_tests::add_cluster_of_a_udp_cluster_with_health_off_resets_a_backend_marked_down
- backends::backends_test::a_udp_prober_keeps_its_verdict_when_the_health_check_goes_away

Signed-off-by: Florentin Dubois <[email protected]>
…d health tests

Three tests in lib/src/server.rs carried a recipe that named no
statement to mutate ("nothing to change, it is red on the unfixed
tree"), which only held before the fix. Each now names the statement to
change in the fixed code and the failure it produces:

- server::listener_lifecycle_tests::a_listener_ordered_after_a_soft_stop_is_not_brought_back
  (delete the `shutting_down` guard of `Server::notify_activate_listener`)
- server::listener_lifecycle_tests::a_socket_queued_for_a_removed_listener_is_not_served_by_the_listener_that_reuses_its_token
  (delete the `accept_queue.retain` of the `RemoveListener` arm of
  `Server::notify_proxys`; replacing it with `clear()` turns the second
  assertion red instead)
- server::remove_health_check_tests::add_cluster_of_a_udp_cluster_with_udp_health_keeps_a_backend_marked_down
  (pass `false` to `set_udp_health_prober` in `Server::add_cluster`)

Each mutation was applied and the test seen failing on its own
assertion, then the code was restored. Comments only.

Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS
FlorentinDUBOIS merged commit 22fabdd into main Nov 20, 2026
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