Skip to content

fix: drain confirmed source removals in two phases - #7581

Merged
oferchen merged 1 commit into
masterfrom
fix/daemon-pull-remove-source-two-phase-drain
Sep 1, 2026
Merged

oferchen merged 1 commit into
masterfrom
fix/daemon-pull-remove-source-two-phase-drain

Conversation

@oferchen

@oferchen oferchen commented Sep 1, 2026 •

Copy link
Copy Markdown
Owner

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 SourceRemovalOutcome type and the emit_sender_diagnostic routing #7576 introduced.

What upstream does about drain ordering

Upstream has no drain to order. 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() (main.c:993) and again inside read_final_goodbye() (main.c:997), which still drives read_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_SUCCESS frames keep arriving through the handshake.

The defect

By the time the post-goodbye drain wrote its MSG_ERROR_XFER, the client had written its final NDX_DONE and stopped reading. The frame landed in a dead read window:

topology before after
local copy 23 23
ssh push 23 23
ssh pull 0 23
daemon pull 0 23

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_finalizer splits into read_receiver_goodbye and answer_goodbye_with_finalizer (it survives as the #[cfg(test)] composition of the two, so the existing goodbye tests are unchanged).
  • goodbye_draining_source_removals composes them around two drains:
    • Phase 1, before the sender answers the goodbye - the last moment a diagnostic still reaches a pulling client.
    • Phase 2, after - unlinks the sources confirmed while the handshake ran.
  • Both phases go through the existing emit_sender_diagnostic, the single place got_xfer_error is set and MSG_ERROR_XFER is framed. No second special case.
  • The method returns 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_topology goes RED on exactly the two pulling cells, reproducing the pre-fix table:

a refused --remove-source-files unlink must exit 23 everywhere:
  ssh pull: upstream's sender.c:455-459 text never reached the observing process; on a pull that means it did not cross the wire as MSG_ERROR_XFER while the client was still reading
    stderr: ""
  ssh pull: exit Some(0), want 23 - a refused source unlink is RERR_PARTIAL (sender.c:455-459 -> log.c:337-338 -> cleanup.c:217-218)
    stderr: ""
  daemon pull: upstream's sender.c:455-459 text never reached the observing process; ...
    stderr: ""
  daemon pull: exit Some(0), want 23 - a refused source unlink is RERR_PARTIAL ...
    stderr: ""

Delete phase 2 -> handshake_confirmed_source_is_still_removed_by_the_second_drain goes RED:

a source confirmed DURING the goodbye handshake must still be removed; dropping
the post-goodbye drain leaks exactly this file (sender.c:395 successful_send(),
dispatched inline by io.c:1793-1807)

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_topology and daemon_sender_removes_sources_for_both_spellings) still PASS. On their single-file fixtures every MSG_SUCCESS happens to land before the receiver's goodbye NDX_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 that before_goodbye == 1 and during_goodbye == 1 - an empty phase-2 set fails the assertion rather than passing quietly. It drives goodbye_draining_source_removals, the same method orchestrator::run calls, so deleting a phase in production fails the test.

Verification

  • Four-topology table after the change: local copy 23, ssh push 23, ssh pull 23, daemon pull 23. Every cell also asserts the file was delivered and the source is still present, so no cell can pass on a transfer that never ran or an unlink that was not refused.
  • Fixture is EACCES (chmod 555 on the source parent), not a seccomp EPERM, so the cells mean the same thing on every platform and feature set.
  • cargo fmt --all -- --check clean (and rustfmt --check directly on the touched files).
  • cargo clippy --workspace --all-targets --all-features --no-deps -- -D warnings clean.
  • 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.py exits 0; no new unresolved citations.

@github-actions github-actions Bot added the bug Something isn't working label Sep 1, 2026
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
oferchen force-pushed the fix/daemon-pull-remove-source-two-phase-drain branch from 89287df to baaa1fb Compare September 1, 2026 09:00
@oferchen
oferchen merged commit 5170870 into master Sep 1, 2026
70 checks passed
@oferchen
oferchen deleted the fix/daemon-pull-remove-source-two-phase-drain branch September 1, 2026 14:32
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant