Repository navigation
fix(daemon): keep accepting after one client's session error - #7590
Merged
Merged
Conversation
`join_worker` treated any session error that was not a connection close as
fatal to the accept loop, so a single malformed client took the listener down
for everybody:
DaemonError { exit_code: SocketIo, message: "failed to serve legacy
handshake 127.0.0.1:54215: invalid daemon connection transition:
ModuleSelect -> ModuleSelect" }
A worker runs exactly one session against one accepted socket, so every
outcome it can carry describes that connection and nothing else. The join
point has no fatal class to report, so `join_worker` now returns nothing at
all and logs the failure against the peer instead. Failures of the listening
socket travel a different path - `bind_error` when a listener cannot be bound
or made non-blocking, and the accept engine's `poll` result - and still end
the daemon.
Normal closes (broken pipe, reset, aborted) stay silent, as before.
upstream serves each connection in a forked child, so this failure mode has no
analogue there to port: socket.c:753-765 runs the session in the child, which
ends at `_exit(ret)`, and socket.c:676-684 reaps it with
`waitpid(-1, NULL, WNOHANG)` - a NULL status pointer, so the parent discards
the outcome without inspecting it. The `while (1)` loop at socket.c:724 has no
error exit; `poll` failure (:738), `accept` failure (:748) and `fork` failure
(:766) each keep it running. Only listener setup is fatal, via
`exit_cleanup(RERR_SOCKETIO)` at socket.c:699 and socket.c:715.
The async accept path already logged and continued
(`async_listener.rs:199-205`); the sync path was the outlier.
This was referenced Sep 1, 2026
oferchen
added a commit
that referenced
this pull request
Sep 2, 2026
`## [Unreleased]` last covered the #7304-#7522 era. Measured against the 60 most recently merged pull requests, 44 were absent; of the most recent 45, 43 were absent. Nothing from #7574 onward was recorded at all. Each entry is derived from what the pull request actually landed - the merge commit and the body - not from its title. Three cases where those differ: * #7616 ships far more than the doc-alias correction its body describes: the `upstream_version` pin moves to 3.5.0 and `--version` starts naming `quic`, `sd-notify`, `vmsplice` and `send_zc`. * #7618 also adds the pull-request rustdoc-link job its body says was filed separately, which is what closes the master-only-gate recurrence. * #7602's squash carries the closed #7597 as its first commit, so the directory-obstacle half is recorded under #7602. #7587 is deliberately not recorded. Its merge commit is empty: the change had already landed as #7563, which the section already names. Entries extend the existing Keep a Changelog groups and the bold sub-groupings. Clusters that are one story carry one entry with several references: the FERROR_XFER routing and its two-phase drain (#7576, #7581), the connection-FSM close edge and the accept loop that outlives a session error (#7579, #7590), the three detaching daemon suites (#7578, #7588, #7592), the io_uring and SEND_ZC work (#7593, #7600, #7610), the citation retargets (#7601, #7603, #7604), and the accept-loop pin flake (#7615, #7620). Only `## [Unreleased]` is touched; every released section, including the 3.4.4 statements that were correct when written, is byte-identical.
oferchen
added a commit
that referenced
this pull request
Sep 6, 2026
…ssion ended (#7716) Two coupled changes to the `SessionWorker` seam, both behaviour-neutral under the current thread backing and both prerequisites for a forked one. `is_finished()` + `join_worker(handle)` collapse into `SessionWorker::try_reap(self) -> Result<SessionOutcome, Self>`. Observing that a session ended and collecting its outcome are ONE step, not two. A thread backing can split them; a forked child cannot, because `waitpid(pid, .., WNOHANG)` reports the child's exit AND consumes its status in the same call - a separate predicate would discard the outcome it had just collected, and a second call would get ECHILD. Keeping them together is what lets the backing change without every caller changing with it. Consuming `self` also states the ownership rule the connection slot depends on: reaping a worker is what drops its `max connections` guard, which #7715 made parent-owned. `reap_finished_workers` therefore drains and rebuilds rather than indexing, so the reaped worker is moved out and dropped while a still-running one is handed back untouched. `SessionWorker` deliberately no longer offers a borrowing readiness predicate for a caller to misuse. The three ways a session can end become a named `SessionOutcome` - Ok, Failed, Died - rather than `thread::Result<WorkerResult>`, whose shape is a property of the thread backing alone and is exactly what a fork-backed variant has to replace. `Died` covers a panic that escaped `catch_unwind` today and a fatal signal once a child serves the session. `join_backing` is now the only site that knows a thread is involved. upstream: socket.c:676-684 `sigchld_handler()` reaps with `waitpid(-1, NULL, WNOHANG)` - a NULL status pointer, so upstream's parent discards the session's fate entirely. oc reports it instead, which is why the outcome needs a name; per #7590 none of its variants is fatal to the listener. No behaviour change is intended, and the proof is that #7715's two tests keep their distinct kill signatures across the refactor: - leak the slot through the reap -> BOTH fail - drop the reap-before-capacity call -> ONLY `admission_reaps_before_consulting_the_connection_cap` fails Verified on the pinned 1.88.0 toolchain: daemon 1991/1991 (6 skipped), workspace clippy --all-targets --all-features clean, whole-tree rustfmt clean across 3422 files.
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.
The defect
join_workertreated any session error that was not a connection close as fatal to the accept loop. One malformed client killed the listener for everybody:Upstream has no mechanism to port here
Upstream serves each connection in a forked child process, so a session outcome physically cannot reach the parent's accept loop. oc-rsync uses threads, so this failure mode is ours alone and the fix has to be reasoned out rather than copied. What upstream establishes is the contract, at the 3.5.0 pin:
socket.c:697-699open_socket_in()returns NULL ->exit_cleanup(RERR_SOCKETIO)socket.c:708-716listen()fails ->exit_cleanup(RERR_SOCKETIO)socket.c:724while (1)- the loop body has no error exitsocket.c:738poll(...) < 1->continuesocket.c:748accept()failed (fd < 0) ->continuesocket.c:753-765fn(fd, fd), ends at_exit(ret)socket.c:766-773fork()failed -> log, close fd, keep loopingsocket.c:676-684sigchld_handler()reaps withwaitpid(-1, NULL, WNOHANG)- NULL status pointer, so the session's outcome is discarded outrightThe contract: only listener setup can end the daemon. No per-connection outcome, of any kind, is even inspected.
Error classification
Everything
join_workercan observe originates inspawn_connection_worker's closure, which callsConnectionContext::serve_session->handle_sessionon the accepted client socket. There is no other producer of aWorkerResult.BrokenPipe/ConnectionReset/ConnectionAbortedhandle_session->parse_proxy_headeron the client sockethandle_legacy_sessionon the client sockettransition_error)handle_legacy_session, protocol state of that one sessioncatch_unwindlisten/set_nonblockingfailurebind_error, engine constructionpollresultAcceptEngine::pollThe last two rows never travel through a
JoinHandle. So the join point observes zero listener-fatal classes.The fix
join_worker,reap_finished_workersanddrain_workersreturn()rather thanResult. The invariant is stated in the type: the join path has no channel through which it could end the accept loop.check_signals_and_maintainlikewise drops itsResult- nothing that step does can fail the daemon.This is not "swallow everything". Listener-fatal errors are on a different path entirely and still propagate out of
serve_connections; a daemon whose listening socket is genuinely broken still exits rather than spinning. Per-connection errors are logged at error level against the peer, keeping the operator-visible text (failed to serve legacy handshake <peer>: <error>) byte-identical to what previously came back as aDaemonError, so existing log greps keep working.stream_errorhad no other caller and is removed.Note the async accept path already logged-and-continued (
async_listener.rs:199-205). The sync path was the outlier.Verification
New
tests/daemon_session_error_keeps_listener.rs: client one drivesModuleSelect -> ModuleSelectby repeating the@RSYNCD:banner; client two then completes a real push throughcore::client::run_clientagainst the same listener. Asserted on the landed bytes, not on the absence of a crash.Non-vacuity is asserted explicitly: the daemon must have logged exactly one
failed to serve legacy handshake ... invalid daemon connection transitionline, and the first client must have been dropped mid-session rather than answered. If the daemon ever starts handling a repeated banner cleanly, this test fails loudly rather than passing while proving nothing. (The first fixture attempt sent a bare@RSYNCD: 32.0, which protocol 32 refuses for the missing digest list - a clean@ERROR, no session error at all. That inert version is what these assertions catch.)The test passes
--no-detachexplicitly. Without itRuntimeOptions::detachdefaults to true on Unix, the daemon forks, and the parent of that fork is the test process, which exits 0 before any assertion runs - the test binary reported PASS in 0.013s with the body never executing.Mutation proof. With the production change reverted and the test kept:
The second client gets
Connection refused: the listener is gone. With the fix restored:Also added a unit test pinning the classification directly:
reap_finished_workersdrains a worklist of four differently-failed sessions and hands back nothing the accept loop could act on.Gates
cargo fmt --all -- --checkclean;tools/ci/check_rustfmt_all.pyclean (3368 files - the changed files areinclude!d and invisible to plaincargo fmt).cargo clippy --workspace --all-targets --all-features --no-deps -- -D warningsclean.tools/ci/citation_drift_audit.pyexit 0.tools/ci/check_daemon_no_detach.shclean, pending ceiling unchanged at 77.cargo nextest run -p daemon --all-features: 1897 tests run: 1897 passed (1 leaky), 6 skipped.cargo nextest run -p bin --all-features -E 'binary(/daemon/)': 78 tests run: 78 passed, 1 skipped.