Skip to content

fix: reuse TokenReader across files for zstd continuous stream compatibility - #3113

Merged
oferchen merged 3 commits into
masterfrom
fix/daemon-zstd-receive-codec
Apr 5, 2026
Merged

oferchen merged 3 commits into
masterfrom
fix/daemon-zstd-receive-codec

Conversation

@oferchen

@oferchen oferchen commented Apr 5, 2026

Copy link
Copy Markdown
Owner

Summary

  • Reuse a single TokenReader across all files in a transfer session instead of creating a new one per file, preserving the zstd ZSTD_DCtx across file boundaries
  • Upstream rsync uses a single continuous zstd stream - the sender never reinitializes its CCtx between files, so creating a new DCtx per file caused decompression failures on the second file
  • Remove up:compress-zstd from KNOWN_FAILURES - this was the last remaining interop test failure

Details

Root cause: process_file_response_streaming() in streaming.rs called ctx.config.token_reader() which created a brand new TokenReader::new(Zstd) with a fresh ZSTD_DCtx for every file. The new DCtx expected a fresh zstd frame header but received continuation data from the ongoing stream.

Fix: Create the TokenReader once in the pipeline loop (pipeline.rs) and pass it as &mut TokenReader to each per-file process_file_response_streaming() call. Between files, token_reader.reset() is called which preserves the zstd DCtx while resetting per-file token state (matching upstream token.c:807-810 r_init behavior). The same change is applied to the non-streaming process_file_response() for consistency.

Upstream reference: token.c:807-810 - zstd r_init only resets rx_token to 0, never reinitializes the ZSTD_DCtx.

Test plan

  • CI: fmt+clippy passes (no unused import warnings from refactored pub use)
  • CI: nextest passes on all platforms (Linux, macOS, Windows)
  • CI: up:compress-zstd interop test passes (upstream rsync pushes with --compress-choice=zstd to oc-rsync daemon)
  • CI: All other interop tests remain passing (zlib/lz4 compression unaffected - they use per-file streams)

…ibility

Upstream rsync uses a single continuous zstd stream across all files in a
transfer session - the sender never reinitializes its ZSTD_CCtx between
files. The receiver must use the same ZSTD_DCtx across file boundaries.

Previously, process_file_response_streaming() created a new TokenReader
per file via ctx.config.token_reader(), allocating a fresh ZSTD_DCtx each
time. The new DCtx expected a fresh zstd frame but received continuation
data from the ongoing stream, causing decompression failures.

Fix: create the TokenReader once in the pipeline loop and pass it to each
per-file call. Between files, call token_reader.reset() which preserves
the zstd DCtx while resetting per-file token state (matching upstream
token.c:807-810 r_init behavior).

Remove up:compress-zstd from KNOWN_FAILURES as this was the last remaining
interop test failure.
@github-actions github-actions Bot added the bug Something isn't working label Apr 5, 2026
oferchen added a commit that referenced this pull request Apr 5, 2026
Advertise zstd and lz4 in the capability negotiation string when their
respective feature flags are enabled. Previously these algorithms were
only usable via explicit --compress-choice and were intentionally
excluded from auto-negotiation pending daemon receive codec validation.

With PR #3113 fixing the daemon receive codec, auto-negotiation can
safely select zstd/lz4 when both peers support them. The preference
order matches upstream compat.c:100-112: zstd > lz4 > zlibx > zlib > none.

Closes #1379, closes #1380.
- Remove unused `TokenReader` import from pipeline.rs (not needed since
  the type is inferred from `create_token_reader()` return value)
- Fix `&mut token_reader` where `token_reader` is already `&mut TokenReader`
  in streaming.rs (was creating `&mut &mut TokenReader`)
@oferchen
oferchen merged commit 9db60fb into master Apr 5, 2026
43 checks passed
@oferchen
oferchen deleted the fix/daemon-zstd-receive-codec branch April 5, 2026 22:05
oferchen added a commit that referenced this pull request Apr 6, 2026
Advertise zstd and lz4 in the capability negotiation string when their
respective feature flags are enabled. Previously these algorithms were
only usable via explicit --compress-choice and were intentionally
excluded from auto-negotiation pending daemon receive codec validation.

With PR #3113 fixing the daemon receive codec, auto-negotiation can
safely select zstd/lz4 when both peers support them. The preference
order matches upstream compat.c:100-112: zstd > lz4 > zlibx > zlib > none.

Closes #1379, closes #1380.
oferchen added a commit that referenced this pull request Apr 6, 2026
Advertise zstd and lz4 in the capability negotiation string when their
respective feature flags are enabled. Previously these algorithms were
only usable via explicit --compress-choice and were intentionally
excluded from auto-negotiation pending daemon receive codec validation.

With PR #3113 fixing the daemon receive codec, auto-negotiation can
safely select zstd/lz4 when both peers support them. The preference
order matches upstream compat.c:100-112: zstd > lz4 > zlibx > zlib > none.

Closes #1379, closes #1380.
oferchen added a commit that referenced this pull request May 1, 2026
…ibility (#3113)

* fix: reuse TokenReader across files for zstd continuous stream compatibility

Upstream rsync uses a single continuous zstd stream across all files in a
transfer session - the sender never reinitializes its ZSTD_CCtx between
files. The receiver must use the same ZSTD_DCtx across file boundaries.

Previously, process_file_response_streaming() created a new TokenReader
per file via ctx.config.token_reader(), allocating a fresh ZSTD_DCtx each
time. The new DCtx expected a fresh zstd frame but received continuation
data from the ongoing stream, causing decompression failures.

Fix: create the TokenReader once in the pipeline loop and pass it to each
per-file call. Between files, call token_reader.reset() which preserves
the zstd DCtx while resetting per-file token state (matching upstream
token.c:807-810 r_init behavior).

Remove up:compress-zstd from KNOWN_FAILURES as this was the last remaining
interop test failure.

* style: apply cargo fmt

* fix: remove unused TokenReader import and fix double-mut reference

- Remove unused `TokenReader` import from pipeline.rs (not needed since
  the type is inferred from `create_token_reader()` return value)
- Fix `&mut token_reader` where `token_reader` is already `&mut TokenReader`
  in streaming.rs (was creating `&mut &mut TokenReader`)
oferchen added a commit that referenced this pull request May 5, 2026
…ibility (#3113)

* fix: reuse TokenReader across files for zstd continuous stream compatibility

Upstream rsync uses a single continuous zstd stream across all files in a
transfer session - the sender never reinitializes its ZSTD_CCtx between
files. The receiver must use the same ZSTD_DCtx across file boundaries.

Previously, process_file_response_streaming() created a new TokenReader
per file via ctx.config.token_reader(), allocating a fresh ZSTD_DCtx each
time. The new DCtx expected a fresh zstd frame but received continuation
data from the ongoing stream, causing decompression failures.

Fix: create the TokenReader once in the pipeline loop and pass it to each
per-file call. Between files, call token_reader.reset() which preserves
the zstd DCtx while resetting per-file token state (matching upstream
token.c:807-810 r_init behavior).

Remove up:compress-zstd from KNOWN_FAILURES as this was the last remaining
interop test failure.

* style: apply cargo fmt

* fix: remove unused TokenReader import and fix double-mut reference

- Remove unused `TokenReader` import from pipeline.rs (not needed since
  the type is inferred from `create_token_reader()` return value)
- Fix `&mut token_reader` where `token_reader` is already `&mut TokenReader`
  in streaming.rs (was creating `&mut &mut TokenReader`)
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