Skip to content

fix(transfer): flush -zz codec state before daemon-sender goodbye (UTS-9.REOPEN) - #5725

Merged
oferchen merged 2 commits into
masterfrom
fix/uts9-reopen-zz-goodbye-flush
Jun 12, 2026
Merged

oferchen merged 2 commits into
masterfrom
fix/uts9-reopen-zz-goodbye-flush

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • The previous UTS-9.REOPEN landing (PR fix(transfer): flush zlib end-of-stream before daemon-sender close (UTS-9.REOPEN) #5710) called ServerWriter::finalize_compression() AFTER handle_goodbye returned, but under -zz daemon pull handle_goodbye deadlocks: the sender blocks on the receiver's final NDX_DONE while the receiver blocks on an unterminated deflate block held in our CompressedWriter buffer. The receiver surfaces this as "connection unexpectedly closed (612423 bytes received so far) [receiver]" once the daemon times out and FINs - the same shape as UTS-9.REOPEN.4 / UTS-15.c, but on the compressed daemon-pull path.
  • Mirror upstream's main.c:979-983 do_server_sender() flush-bracketing of read_final_goodbye() by introducing handle_goodbye_with_finalizer. It runs a caller-supplied hook BETWEEN the goodbye write+flush and the goodbye read. The generator orchestrator passes |w| w.finalize_compression() so the deflate end-of-stream trailer ships before the receiver is asked to decompress past the closing block (matching token.c:367 send_deflated_token()'s end-of-transfer deflateEnd() contract). Upstream's NDX_DONE rides through io.c:2255 write_buf() uncompressed; our writer-graph routes it through CompressedWriter, so we additionally need to drive the codec finalisation here.
  • A regression test asserts the new ordering invariant: the finalizer must observe the goodbye NDX_DONE already in the wire buffer AND must run before the final receiver NDX_DONE is consumed. Without this, the prior fix's post-goodbye finalisation is unreachable.

What this preserves

  • UTS-9.REOPEN.4 / UTS-15.c: the legacy handle_goodbye flush-before-close contract is preserved. The non-finalizer variant delegates with a no-op hook, and the existing handle_goodbye_proto31_flushes_ndx_done_before_close FlushTrackingWriter test still asserts last_op_was_flush and trailing NDX_DONE bytes.
  • IUS-4 / SZC SEND_ZC: no changes to data-phase send paths or zero-copy dispatch.
  • Defense-in-depth finalize_compression() call after the goodbye still runs (idempotent on Multiplex, degrades to a plain flush) so trailing MSG_INFO frames still ship before FIN.

Test plan

  • New handle_goodbye_with_finalizer_runs_between_write_and_read regression test in crates/transfer/src/generator/tests.rs pins the write-then-finalize-then-read ordering using a TrackingReader + thread-local byte counter.
  • Existing server_writer_finalize_compression_* tests in crates/transfer/src/writer/tests.rs still cover zlib end-of-stream decode round-trip on the receiver side.
  • Existing handle_goodbye_proto31_flushes_ndx_done_before_close test still passes through the no-op-finalizer delegate (handle_goodbye -> handle_goodbye_with_finalizer(...|_w| Ok(()))).
  • CI Linux runtests daemon-gzip-download upstream interop case.

@github-actions github-actions Bot added the bug Something isn't working label Jun 12, 2026
oferchen added a commit that referenced this pull request Jun 12, 2026
* chore: fix master fmt drift + filter_map_bool_then clippy lint

Master CI broke on rustfmt 1.88 and clippy 1.88:

1. `crates/cli/src/frontend/server/run.rs:244` - `use fast_io::landlock::{...}`
   collapses to a single line under rustfmt 1.88 (introduced by PR #5724's
   landlock wire-in).
2. `crates/transfer/src/generator/filters.rs:589` - `let split = ...` long-form
   collapses to single-line under rustfmt 1.88.
3. `crates/transfer/src/generator/file_list/mod.rs:267` - rewrite
   `filter_map(|(b, rel)| (b == &entry.base).then(|| rel.clone()))` as the
   equivalent `filter(...).map(...)` pair so clippy 1.88's new
   `filter_map_bool_then` lint stays clean. Behaviour-identical.

Unblocks PRs #5725, #5726, #5727 once they rebase onto this.

* fix: drop extraneous deref in filter predicate

In .filter(), the destructured 'b' is already &PathBuf since iter() yields
&(PathBuf, PathBuf) and filter receives &Self::Item. The extra deref made it
PathBuf, causing E0277 'can't compare PathBuf with &PathBuf'.

* chore(cli): inline format args in --partial-dir test (clippy 1.88)

uninlined_format_args lint denies the build under clippy 1.88.
oferchen added 2 commits June 12, 2026 04:40
…S-9.REOPEN)

The previous UTS-9.REOPEN landing called `ServerWriter::finalize_compression()`
after `handle_goodbye` returned, but under `-zz` daemon pull
`handle_goodbye` never returns: the sender blocks on the receiver's
final NDX_DONE while the receiver blocks on an unterminated deflate
block held in our `CompressedWriter` buffer. The receiver surfaces this
as "connection unexpectedly closed (N bytes received so far) [receiver]"
once the daemon times out and FINs.

Mirror upstream's `main.c:979-983 do_server_sender()` flush-bracketing
of `read_final_goodbye()` by introducing
`handle_goodbye_with_finalizer`, which runs a caller-supplied hook
between the goodbye write+flush and the goodbye read. The generator
orchestrator passes `|w| w.finalize_compression()` so the deflate
end-of-stream trailer ships before the receiver is asked to decompress
past the closing block. Upstream's NDX_DONE rides through
`io.c:2255 write_buf()` (uncompressed); our writer-graph routes it
through `CompressedWriter`, so we additionally need
`token.c:367 send_deflated_token()`'s end-of-transfer `deflateEnd()`
contract honoured here.

A regression test in the generator unit-test module asserts the new
ordering invariant: the finalizer must observe the goodbye NDX_DONE in
the wire buffer (write side complete) AND must run before the final
receiver NDX_DONE is consumed (read side not yet started). Without
this, the prior fix's post-goodbye finalisation is unreachable.

UTS-9.REOPEN.4 / UTS-15.c (legacy `handle_goodbye` flush-before-close
contract) are preserved: the non-finalizer variant delegates with a
no-op hook, and the existing FlushTrackingWriter test still asserts
`last_op_was_flush`. IUS-4 / SZC SEND_ZC behaviour is unaffected
(no changes to data-phase send paths).
The handle_goodbye wrapper is only invoked from generator tests; production
orchestrator calls handle_goodbye_with_finalizer directly. Under
--features async the unused-method lint denies the build.
@oferchen
oferchen force-pushed the fix/uts9-reopen-zz-goodbye-flush branch from 1e0a7db to e8299ca Compare June 12, 2026 01:40
@oferchen
oferchen merged commit 32e465f into master Jun 12, 2026
54 of 68 checks passed
@oferchen
oferchen deleted the fix/uts9-reopen-zz-goodbye-flush branch June 12, 2026 02:26
oferchen added a commit that referenced this pull request Jun 19, 2026
Adds the cross-binary upstream-compat harness primitives specified by
NXT-1 (`UpstreamVersion`, `locate_upstream_rsync`, `require_upstream_rsync`,
`upstream_compat_enabled`) and ports the upstream `daemon-gzip-download.test`
goodbye-flush invariant into nextest.

The test pairs an upstream rsync 3.4.4 client against an oc-rsync daemon
over TCP and pulls a ~1 MB `-zz`-compressed fixture sized to clear the
UTS-9 ~615 KB cutoff. The invariant pinned is that the daemon-sender
goodbye envelope reaches the upstream client without a premature
connection drop - the regression family fixed by PRs #5520 / #5600 /
#5619 / #5725.

Self-skips on three conditions: `OC_RSYNC_UPSTREAM_COMPAT` env var
unset (default for PR cells), upstream rsync 3.4.4 binary not present
at `target/interop/upstream-install/3.4.4/bin/rsync`, or the oc-rsync
binary cannot be located. Wall-time impact on the standard PR cell is
a single early-return.

NXT-1 calls out that the new `upstream-compat` CI cell is the wire-up
step that flips the env var on. That cell does not exist yet; this PR
ships the test and harness only, and a follow-up will add the matrix
entry to the existing nextest workflow.

Refs: docs/design/nxt-1-nextest-harness.md
oferchen added a commit that referenced this pull request Jun 19, 2026
…6002)

Adds the cross-binary upstream-compat harness primitives specified by
NXT-1 (`UpstreamVersion`, `locate_upstream_rsync`, `require_upstream_rsync`,
`upstream_compat_enabled`) and ports the upstream `daemon-gzip-download.test`
goodbye-flush invariant into nextest.

The test pairs an upstream rsync 3.4.4 client against an oc-rsync daemon
over TCP and pulls a ~1 MB `-zz`-compressed fixture sized to clear the
UTS-9 ~615 KB cutoff. The invariant pinned is that the daemon-sender
goodbye envelope reaches the upstream client without a premature
connection drop - the regression family fixed by PRs #5520 / #5600 /
#5619 / #5725.

Self-skips on three conditions: `OC_RSYNC_UPSTREAM_COMPAT` env var
unset (default for PR cells), upstream rsync 3.4.4 binary not present
at `target/interop/upstream-install/3.4.4/bin/rsync`, or the oc-rsync
binary cannot be located. Wall-time impact on the standard PR cell is
a single early-return.

NXT-1 calls out that the new `upstream-compat` CI cell is the wire-up
step that flips the env var on. That cell does not exist yet; this PR
ships the test and harness only, and a follow-up will add the matrix
entry to the existing nextest workflow.

Refs: docs/design/nxt-1-nextest-harness.md
oferchen added a commit that referenced this pull request Aug 24, 2026
* chore: fix master fmt drift + filter_map_bool_then clippy lint

Master CI broke on rustfmt 1.88 and clippy 1.88:

1. `crates/cli/src/frontend/server/run.rs:244` - `use fast_io::landlock::{...}`
   collapses to a single line under rustfmt 1.88 (introduced by PR #5724's
   landlock wire-in).
2. `crates/transfer/src/generator/filters.rs:589` - `let split = ...` long-form
   collapses to single-line under rustfmt 1.88.
3. `crates/transfer/src/generator/file_list/mod.rs:267` - rewrite
   `filter_map(|(b, rel)| (b == &entry.base).then(|| rel.clone()))` as the
   equivalent `filter(...).map(...)` pair so clippy 1.88's new
   `filter_map_bool_then` lint stays clean. Behaviour-identical.

Unblocks PRs #5725, #5726, #5727 once they rebase onto this.

* fix: drop extraneous deref in filter predicate

In .filter(), the destructured 'b' is already &PathBuf since iter() yields
&(PathBuf, PathBuf) and filter receives &Self::Item. The extra deref made it
PathBuf, causing E0277 'can't compare PathBuf with &PathBuf'.

* chore(cli): inline format args in --partial-dir test (clippy 1.88)

uninlined_format_args lint denies the build under clippy 1.88.
oferchen added a commit that referenced this pull request Aug 24, 2026
…S-9.REOPEN) (#5725)

* fix(transfer): flush -zz codec state before daemon-sender goodbye (UTS-9.REOPEN)

The previous UTS-9.REOPEN landing called `ServerWriter::finalize_compression()`
after `handle_goodbye` returned, but under `-zz` daemon pull
`handle_goodbye` never returns: the sender blocks on the receiver's
final NDX_DONE while the receiver blocks on an unterminated deflate
block held in our `CompressedWriter` buffer. The receiver surfaces this
as "connection unexpectedly closed (N bytes received so far) [receiver]"
once the daemon times out and FINs.

Mirror upstream's `main.c:979-983 do_server_sender()` flush-bracketing
of `read_final_goodbye()` by introducing
`handle_goodbye_with_finalizer`, which runs a caller-supplied hook
between the goodbye write+flush and the goodbye read. The generator
orchestrator passes `|w| w.finalize_compression()` so the deflate
end-of-stream trailer ships before the receiver is asked to decompress
past the closing block. Upstream's NDX_DONE rides through
`io.c:2255 write_buf()` (uncompressed); our writer-graph routes it
through `CompressedWriter`, so we additionally need
`token.c:367 send_deflated_token()`'s end-of-transfer `deflateEnd()`
contract honoured here.

A regression test in the generator unit-test module asserts the new
ordering invariant: the finalizer must observe the goodbye NDX_DONE in
the wire buffer (write side complete) AND must run before the final
receiver NDX_DONE is consumed (read side not yet started). Without
this, the prior fix's post-goodbye finalisation is unreachable.

UTS-9.REOPEN.4 / UTS-15.c (legacy `handle_goodbye` flush-before-close
contract) are preserved: the non-finalizer variant delegates with a
no-op hook, and the existing FlushTrackingWriter test still asserts
`last_op_was_flush`. IUS-4 / SZC SEND_ZC behaviour is unaffected
(no changes to data-phase send paths).

* fix(transfer): gate test-only handle_goodbye wrapper under cfg(test)

The handle_goodbye wrapper is only invoked from generator tests; production
orchestrator calls handle_goodbye_with_finalizer directly. Under
--features async the unused-method lint denies the build.
oferchen added a commit that referenced this pull request Aug 24, 2026
…6002)

Adds the cross-binary upstream-compat harness primitives specified by
NXT-1 (`UpstreamVersion`, `locate_upstream_rsync`, `require_upstream_rsync`,
`upstream_compat_enabled`) and ports the upstream `daemon-gzip-download.test`
goodbye-flush invariant into nextest.

The test pairs an upstream rsync 3.4.4 client against an oc-rsync daemon
over TCP and pulls a ~1 MB `-zz`-compressed fixture sized to clear the
UTS-9 ~615 KB cutoff. The invariant pinned is that the daemon-sender
goodbye envelope reaches the upstream client without a premature
connection drop - the regression family fixed by PRs #5520 / #5600 /
#5619 / #5725.

Self-skips on three conditions: `OC_RSYNC_UPSTREAM_COMPAT` env var
unset (default for PR cells), upstream rsync 3.4.4 binary not present
at `target/interop/upstream-install/3.4.4/bin/rsync`, or the oc-rsync
binary cannot be located. Wall-time impact on the standard PR cell is
a single early-return.

NXT-1 calls out that the new `upstream-compat` CI cell is the wire-up
step that flips the env var on. That cell does not exist yet; this PR
ships the test and harness only, and a follow-up will add the matrix
entry to the existing nextest workflow.

Refs: docs/design/nxt-1-nextest-harness.md
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