Repository navigation
fix(daemon): make the connection close edge total - #7579
Merged
Merged
Conversation
The `ConnectionState` FSM validated its transitions and then threw the result away at four of ten call sites: two `let _ = ...transition(...)` and two `_ = ...transition(...)?` that dropped the new state. Every one of those sites targeted `Closing`, which is reachable from every state, so the `Result` they discarded could never have been `Err`. Split the two kinds of edge instead of papering over one with the other. `transition` now covers only the handshake progression (Greeting -> ModuleSelect -> Authenticating -> Transferring) and rejects `Closing` outright, so every remaining call site is a real ordering constraint whose error is propagated. Teardown becomes `close()`, which is total and returns the state directly - there is nothing left to discard. In the session handler the four teardown points collapse into one `end_session`, which forwards the exit code and asserts the session was not already closed. Closing the loop this way exposed the FSM's one peer-driven edge. A second `@RSYNCD:` banner made the handler take Greeting -> ModuleSelect twice, which the ordering check rejects; that error is not survivable, because `join_worker` treats any session error that is not a connection close as fatal to the listener, so two greeting lines ended the daemon. Upstream reads the version line exactly once in `exchange_protocols()` and takes the very next line as the request whatever it contains (clientserver.c:1534-1538), so a repeated banner is a module name and draws `@ERROR: Unknown module` (:1563-1567). Match that: the version arm is guarded on `negotiated_protocol.is_none()` and a later banner falls through to the request.
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.
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.
What
The daemon's
ConnectionStateFSM validated each transition and then discarded the result at four of its ten production call sites. This makes the close edge total so there is nothing left to discard, and fixes the one peer-reachable failure the audit uncovered.Call-site inventory (10 production sites)
session_runtime.rs:331-> Closing(malformed greeting refusal)let _ =)session_runtime.rs:369-> Closing(client@RSYNCD: EXIT)let _ =)session_runtime.rs:415-> Closing(after#list)_ = ...?)session_runtime.rs:430-> Closing(unknown command)_ = ...?)session_runtime.rs:356Greeting -> ModuleSelectrequest.rs:560-> Authenticatingrequest.rs:578-> Closing(unsupported auth digest)request.rs:607-> Closing(auth failure)orchestration.rs:774-> Transferringorchestration.rs:971Transferring -> ClosingEvery discarded site targeted
Closing.Closingwas reachable from every non-terminal state, and none of these paths could already be closing, so the discardedResultcould never have beenErr. Discarding was harmless and the check was inert - the guard existed and could not run.Change
Separate the two kinds of edge instead of expressing one through the other:
transitionnow covers only the handshake progression -Greeting -> ModuleSelect -> Authenticating -> Transferring- and rejectsClosingas a target. Every remaining call site is a genuine ordering constraint whose error is propagated.close()is the teardown edge. It is total from every state, returnsConnectionStaterather thanResult, and is a no-op on an already-closing connection, matching upstream's deliberately re-entrant_exit_cleanup()(cleanup.c:103).handle_legacy_sessionthe four teardown points collapse into oneend_session, which forwards the session exit code and asserts the handler had not already closed.The bug this exposed
session_runtime.rs:356is the only edge a peer can aim at the FSM. A second@RSYNCD:banner made the handler takeGreeting -> ModuleSelecttwice; the ordering check rejected it and the resultingio::Erroris not survivable -join_worker(server_runtime/workers.rs) treats any session error that is not a connection close as fatal to the accept loop. Two greeting lines ended the daemon:Upstream reads the version line exactly once, in
exchange_protocols(), and takes the very nextread_line_old()as the request whatever it contains (clientserver.c:1534-1538). A repeated banner is therefore a module name and draws@ERROR: Unknown module(:1563-1567). The version arm is now guarded onnegotiated_protocol.is_none()and a later banner falls through to the request, which fixes both the refusal shape and the listener teardown.Tests
crates/daemon/tests/connection_lifecycle_fsm.rs::lifecycle_repeated_version_line_is_a_module_namedrives a real daemon, sends two banners and a#list, and asserts the upstream refusal, that the#listis never served, and that the accept loop survives.Unit level:
transition_never_targets_closingandclose_is_total_from_every_statepin the split;exhaustive_transition_matrixandconnection_state_is_sole_lifecycle_authorityare updated to the progression-only table.Mutation proof
negotiated_protocol.is_none()guardlifecycle_repeated_version_line_is_a_module_nameFAILS (got: ""- the daemon died); other 7 tests in the binary stay greenclose()returnsselfinstead ofClosingclose_is_total_from_every_stateamong them; all 8 protocol-level lifecycle tests stay green, confirming the FSM writes are unobservable on the wireClosingtovalid_transitions(Greeting)transition_never_targets_closing,exhaustive_transition_matrix,valid_transitions_greetingFAIL; other 60 stay greenVerification
cargo nextest run -p daemon --all-features- 1894 passed, 6 skippedcargo nextest run -p bin --all-features -E 'binary(/daemon/)'- 77 passedcargo test -p daemon --doc- 10 passedcargo fmt --all -- --checkandrustfmt --checkdirectly on all six touched files - cleancargo clippy --workspace --all-targets --all-features --no-deps -- -D warnings- cleanFollow-ups, not fixed here
join_workermaking any non-connection-close session error fatal to the listener is a general availability hazard well beyond the FSM; it deserves its own change and tests.handle_unknown_moduleandhandle_module_deniedreturn before any teardown edge is taken, so those paths never recordClosing. Harmless today because nothing reads the state, but it is a gap in the model.OPTION --xxxlines that upstream'sstart_daemonnever reads, an oc-only extension to the handshake.