Repository navigation
Description
Summary
On a worker upgrade, a listener's inherited file descriptor is closed unused instead of being
adopted. All four protocols. The address keeps being served because of SO_REUSEPORT, so there is no
outage — what is lost is the point of the hand-off: whatever was queued on the inherited socket.
Mechanism
XxxListener::activate short-circuits before it can consume the socket it was handed:
lib/src/http.rs:1295,lib/src/https.rs:1433,lib/src/tcp.rs:2377,lib/src/udp.rs:287all open
withif self.active { return Ok(self.token); }.
The caller has already built an owning wrapper around the inherited fd
(.map(|fd| unsafe { MioUdpSocket::from_raw_fd(fd) }) and the TCP equivalents), and
ScmListeners::get_* (command/src/scm_socket.rs:473-528) removes the entry as it hands it over.
So on the early return the wrapper is dropped and the fd is closed, with the entry already consumed.
Why it is reachable on an ordinary upgrade
Not an exotic path — it is the normal sequence:
fork_main_into_workerwrites the initial state fromproduce_initial_state
(command/src/state.rs:2737), which isgenerate_requests()— including oneActivateListener
per active listener.Server::try_new_from_configapplies that initial state (lib/src/server.rs:958) before
receive_listeners()(lib/src/server.rs:1005).scm_listenersis stillNone, so the new
worker binds its own socket, which succeeds becauseserver_bind/udp_bindset
SO_REUSEPORT(lib/src/socket.rs:1136,:1213). The listener is nowactive.server.scm_listeners = Some(listeners)(lib/src/server.rs:1020) — the old worker's fds arrive
after the listener is already up.UpgradeWorkerTaskscattersgenerate_activate_requests()to the new worker
(bin/src/command/upgrade.rs:177-185). Repeat activate → short-circuit → the inherited fd is
closed unused, once per listener, on every protocol.
Impact
Medium. It is a close, not a leak, and SO_REUSEPORT means the address stays served by the worker's
own socket. What is lost is the queued state the hand-off exists to preserve:
- TCP / HTTP / HTTPS: the inherited accept backlog is discarded — connections that completed their
handshake against the old socket get an RST instead of being served. - UDP: the inherited receive buffer is dropped. Mitigating:
lib/src/protocol/udp/LIFECYCLE.md:353-356
already documents that UDP flow state is deliberately not migrated, so the expectation there is
lower.
Note on from_scm
The from_scm field is dead — zero from_scm: true anywhere in the tree, and nothing reads it. It is
not the gate. The real condition is scm_listeners still holding an unconsumed fd for a listener that
is already active.
Suggested direction
Give the four activate implementations an early-return path that hands the socket back to the caller
rather than dropping it, so the caller can either adopt it or close it deliberately. Whether an
already-active listener should replace its socket with the inherited one, or explicitly discard it
after draining, is the design question — replacing mid-flight has its own hazards, so this wants a
decision rather than a reflex.
Provenance
Found while fixing a separate defect in the UDP ActivateListener arm; not introduced by that work.
Source-derived — the upgrade path was traced through the code, not reproduced on a live upgrade.
Confirming it with an actual sozu upgrade and an ss/lsof observation of the inherited fd would be
worthwhile before choosing a fix.
Activity
fix(upgrade): adopt the inherited listener sockets instead of closing…
fix(upgrade): adopt the inherited listener sockets instead of closing…
fix(upgrade): adopt the inherited listener sockets instead of closing…
fix(upgrade): adopt the inherited listener sockets instead of closing…
fix(upgrade): adopt the inherited listener sockets instead of closing…