Repository navigation
fix: drain confirmed source removals in two phases - #7581
Merged
Merged
Conversation
Base automatically changed from
fix/sender-remove-source-ferror-xfer
to
master
September 1, 2026 08:44
Upstream never batches its `--remove-source-files` unlinks: `read_a_msg()` calls `successful_send(val)` the instant it demultiplexes a `MSG_SUCCESS` frame (io.c:1793-1807), so the unlink - and the `FERROR_XFER` a refused unlink raises (sender.c:455-462) - happens wherever the sender is doing I/O, inside `send_files()` and again inside `read_final_goodbye()` (main.c:997). It is always written while the peer is still reading. Our reader accumulates the confirmations instead of dispatching them, and the single drain sat after the whole goodbye exchange. By then the client had written its final `NDX_DONE` and stopped reading, so the `MSG_ERROR_XFER` frame landed in a dead read window and both pulling topologies reported success for a destructive-intent option that had not done its job: | topology | before | after | |-------------|--------|-------| | local copy | 23 | 23 | | ssh push | 23 | 23 | | ssh pull | 0 | 23 | | daemon pull | 0 | 23 | The push and local cells were green throughout because there the failing sender IS the process whose exit code is observed. Simply moving the drain earlier is not the fix: `MSG_SUCCESS` frames keep arriving through the handshake, because the receiver commits and acknowledges its last files after its generator has already sent `NDX_DONE`. Those sources would stop being removed, silently. So reproduce upstream's eagerness by draining at each point upstream would already have reacted. `handle_goodbye_with_finalizer` splits into `read_receiver_goodbye` plus `answer_goodbye_with_finalizer`, and `goodbye_draining_source_removals` composes them around two drains: one before the sender answers the goodbye, whose diagnostics a pulling client still reads, and one after, which unlinks the sources confirmed during the handshake. Both route through the same `emit_sender_diagnostic` that sets `got_xfer_error` and frames `MSG_ERROR_XFER`; no second special case. The method reports each phase's count so a test can tell the two apart. A fixture whose second phase is empty would pass under either shape, so `handshake_confirmed_source_is_still_removed_by_the_second_drain` scripts the receiver's wire byte by byte - one confirmation before the goodbye `NDX_DONE`, one after - and asserts both counts are exactly 1.
oferchen
force-pushed
the
fix/daemon-pull-remove-source-two-phase-drain
branch
from
September 1, 2026 09:00
89287df to
baaa1fb
Compare
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.
Builds on #7576, which has since landed on master (squashed as c19f0ba). This branch is now rebased onto master and targets it directly. It depends on the
SourceRemovalOutcometype and theemit_sender_diagnosticrouting #7576 introduced.What upstream does about drain ordering
Upstream has no drain to order.
read_a_msg()callssuccessful_send(val)the instant it demultiplexes aMSG_SUCCESSframe (io.c:1793-1807), so the unlink - and theFERROR_XFERa refused unlink raises (sender.c:455-462) - happens wherever the sender is doing I/O: insidesend_files()(main.c:993) and again insideread_final_goodbye()(main.c:997), which still drivesread_a_msg(). The reaction is always written while the peer is still reading.Our reader accumulates the confirmations instead of dispatching them, so the single batched drain had a position, and it sat after the whole goodbye exchange - deliberately, because
MSG_SUCCESSframes keep arriving through the handshake.The defect
By the time the post-goodbye drain wrote its
MSG_ERROR_XFER, the client had written its finalNDX_DONEand stopped reading. The frame landed in a dead read window:Both zeros are the same defect. The issue was reported for daemon pull; ssh pull was measured to be equally affected - on a pull the sender is the remote either way. The push and local cells were green throughout because there the failing sender IS the process whose exit code is observed.
The fix: a two-phase drain
Moving the drain earlier is not the fix - the confirmations that arrive during the handshake would stop being acted on and those sources would be silently left behind. Instead, reproduce upstream's eagerness by draining at each point upstream would already have reacted.
handle_goodbye_with_finalizersplits intoread_receiver_goodbyeandanswer_goodbye_with_finalizer(it survives as the#[cfg(test)]composition of the two, so the existing goodbye tests are unchanged).goodbye_draining_source_removalscomposes them around two drains:emit_sender_diagnostic, the single placegot_xfer_erroris set andMSG_ERROR_XFERis framed. No second special case.SourceRemovalDrains { before_goodbye, during_goodbye }so a test can tell the two phases apart.Mutation proofs
Delete phase 1 ->
refused_source_unlink_exits_23_in_every_topologygoes RED on exactly the two pulling cells, reproducing the pre-fix table:Delete phase 2 ->
handshake_confirmed_source_is_still_removed_by_the_second_draingoes RED:Why the phase-2 fixture is not vacuous
Reported honestly, because it matters: with phase 2 deleted, both wire-level integration tests (
refused_source_unlink_exits_23_in_every_topologyanddaemon_sender_removes_sources_for_both_spellings) still PASS. On their single-file fixtures everyMSG_SUCCESShappens to land before the receiver's goodbyeNDX_DONE, so they exercise phase 1 only and say nothing about phase 2. A real-transfer fixture is therefore not a sufficient guard - which is precisely how "move the drain earlier" would have shipped unnoticed.So the phase-2 guard scripts the receiver's wire byte by byte:
MSG_SUCCESS(early),MSG_DATA(NDX_DONE),MSG_SUCCESS(late),MSG_DATA(NDX_DONE).late's confirmation is only demultiplexed by the reads inside the goodbye, so it can only be acted on by phase 2. The test asserts both sources are gone AND thatbefore_goodbye == 1andduring_goodbye == 1- an empty phase-2 set fails the assertion rather than passing quietly. It drivesgoodbye_draining_source_removals, the same methodorchestrator::runcalls, so deleting a phase in production fails the test.Verification
chmod 555on the source parent), not a seccompEPERM, so the cells mean the same thing on every platform and feature set.cargo fmt --all -- --checkclean (andrustfmt --checkdirectly on the touched files).cargo clippy --workspace --all-targets --all-features --no-deps -- -D warningsclean.cargo nextest run -p transfer --all-features: 2777 passed.cargo nextest run -p bin --all-features: 516 passed.cargo nextest run -p core -p daemon --all-features: 4731 passed.tools/ci/citation_drift_audit.pyexits 0; no new unresolved citations.