Skip to content

refactor: delete the unused stream-compression reader and writer - #8260

Merged
oferchen merged 4 commits into
fix/goodbye-barriersfrom
refactor/delete-dead-compressed-writer
Oct 28, 2026
Merged

oferchen merged 4 commits into
fix/goodbye-barriersfrom
refactor/delete-dead-compressed-writer

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

Compression is token-level, as in upstream token.c, so no production path ever wraps the multiplexed stream in a compressor. Nothing outside tests reaches the stream-compression layer.

  • Deleted:
    • ServerWriter::Compressed, activate_compression and activate_compression_with_workers.
    • ServerReader's Compressed inner state and activate_compression.
    • The CompressedWriter and CompressedReader modules, and every match arm forwarding to them.
  • finalize_compression is gone. flush_all_pending is now a flush that tolerates a closed peer, which is what it already did in production.
  • ZstdStrategy::with_workers is gone. It lost its only caller with CompressedWriter, and the dead-code census flags it. The strategy builds its zstd encoder single-threaded, as it already did for every remaining caller.
  • Tests deleted: those that existed only to drive the removed layer (activation-state checks, batch-recorder placement under stream compression, zlib end-of-stream finalisation). Token compression and its tests are untouched.

Test plan

  • cargo clippy --workspace --all-targets --all-features --no-deps -- -D warnings
  • cargo clippy -p transfer -p compress --all-targets --no-default-features -- -D warnings
  • cargo fmt --all -- --check; dead_code_census.py: OK
  • cargo nextest run -p transfer -p compress -p core --all-features: 6911/6911
  • CI

Coordination

Conventional commit prefix

  • refactor:

Pre-merge checklist

  • Conventional commit prefix on PR title matches the change category.
  • No references to internal tooling or non-human authoring aids; hyphens, not em-dashes.

The goodbye handshake ran a finalizer between writing the sender's
NDX_DONE and reading the receiver's reply. It only called
finalize_compression(), which is a plain flush in production: no
production path builds a Compressed ServerWriter, since compression is
token-level as in upstream token.c. It also ran directly after the
flush that follows NDX_DONE, so it could never move a byte. Upstream
has no counterpart either. read_ndx_and_attrs() drains output in
perform_io() before it blocks, which is the existing flush, and
handle_goodbye_proto31_flushes_ndx_done_before_close already guards
it. Remove the finalizer parameter from the goodbye methods.

The orchestrator's exit flush is what upstream requires: main.c:1011
runs io_flush(FULL_FLUSH) after read_final_goodbye(), and
cleanup.c:194-195 flushes again on exit_cleanup(0). That includes the
empty-file-list early return at main.c:996-1001. Below protocol 30,
send_file_list() leaves the list end and the io_error word buffered,
and the multiplex writer has no flushing Drop. Without the flush the
client never receives them. A new run()-level test fails with an
empty wire when that flush is removed.
kill_process_group on Apple treated EPERM as success only once waitid
already reported the leader as ended. A leader that has begun exiting
but is not yet waitable is skipped by XNU's killpg1() too, so the EPERM
can arrive first, and the test harness's Drop panicked with "stop the
test daemon N: Operation not permitted". This was seen on master's macOS
tracing row (daemon_pull_default_send_zc_byte_identical) and on the
iconv row here. EPERM for our own child now blocks in waitid until the
leader has ended, without reaping it.

The empty-file-list flush test relied on ENOTDIR from a path through a
regular file, which Windows reports as not-found, so no io_error was
raised there. Use a missing operand instead. The word is then 0, but the
list end plus four io_error bytes still have to reach the wire, and with
the early-return flush removed the wire carries no data at all.
XNU's killpg1() (bsd/kern/kern_sig.c) returns EPERM for a POSIX caller
whenever it signalled no member of the group. That covers two cases.
In the first, the leader is a zombie or is still exiting and not yet
waitable. In the second, the leader is alive and the only other member
belongs to a different uid. The previous change blocked in
waitid(WEXITED|WNOWAIT) on any EPERM for our own child. In the second
case the leader never exits, so that wait would hang forever.

Now a non-blocking waitid probe first confirms the pid is our own
child; any other pid is never signalled and keeps the EPERM error. The
leader is then killed directly, which is always permitted on one's own
child and harmless on a zombie, and only then awaited without reaping,
so the wait has a bounded end.

Neither case has a deterministic reproduction: the first is a
scheduling window inside process exit, and the second needs a
cross-uid group member. Both follow from the killpg1() return rule.
Compression is token-level, as in upstream token.c, so no production
path ever wrapped the multiplexed stream in a compressor. Nothing
outside tests called ServerWriter::activate_compression*,
ServerReader::activate_compression, CompressedWriter or
CompressedReader. Delete them, their Compressed variants and match
arms, finalize_compression (flush_all_pending is now a flush that
tolerates a closed peer), and the tests that existed only to exercise
them.

ZstdStrategy::with_workers lost its only caller with CompressedWriter,
so it goes too; the strategy builds its encoder single-threaded, which
is what it already did for every caller.
@oferchen
oferchen force-pushed the fix/goodbye-barriers branch from 429ee46 to b5b22a5 Compare October 28, 2026 22:25
@oferchen
oferchen merged commit 5408864 into fix/goodbye-barriers Oct 28, 2026
84 of 87 checks passed
@oferchen
oferchen deleted the refactor/delete-dead-compressed-writer branch October 28, 2026 23:28
oferchen added a commit that referenced this pull request Oct 29, 2026
* fix: guard the sender exit flush and drop the goodbye finalizer

The goodbye handshake ran a finalizer between writing the sender's
NDX_DONE and reading the receiver's reply. It only called
finalize_compression(), which is a plain flush in production: no
production path builds a Compressed ServerWriter, since compression is
token-level as in upstream token.c. It also ran directly after the
flush that follows NDX_DONE, so it could never move a byte. Upstream
has no counterpart either. read_ndx_and_attrs() drains output in
perform_io() before it blocks, which is the existing flush, and
handle_goodbye_proto31_flushes_ndx_done_before_close already guards
it. Remove the finalizer parameter from the goodbye methods.

The orchestrator's exit flush is what upstream requires: main.c:1011
runs io_flush(FULL_FLUSH) after read_final_goodbye(), and
cleanup.c:194-195 flushes again on exit_cleanup(0). That includes the
empty-file-list early return at main.c:996-1001. Below protocol 30,
send_file_list() leaves the list end and the io_error word buffered,
and the multiplex writer has no flushing Drop. Without the flush the
client never receives them. A new run()-level test fails with an
empty wire when that flush is removed.

* fix: wait out an exiting leader on macOS killpg; portable flush fixture

kill_process_group on Apple treated EPERM as success only once waitid
already reported the leader as ended. A leader that has begun exiting
but is not yet waitable is skipped by XNU's killpg1() too, so the EPERM
can arrive first, and the test harness's Drop panicked with "stop the
test daemon N: Operation not permitted". This was seen on master's macOS
tracing row (daemon_pull_default_send_zc_byte_identical) and on the
iconv row here. EPERM for our own child now blocks in waitid until the
leader has ended, without reaping it.

The empty-file-list flush test relied on ENOTDIR from a path through a
regular file, which Windows reports as not-found, so no io_error was
raised there. Use a missing operand instead. The word is then 0, but the
list end plus four io_error bytes still have to reach the wire, and with
the early-return flush removed the wire carries no data at all.

* fix: SIGKILL the leader before awaiting it on a macOS killpg EPERM

XNU's killpg1() (bsd/kern/kern_sig.c) returns EPERM for a POSIX caller
whenever it signalled no member of the group. That covers two cases.
In the first, the leader is a zombie or is still exiting and not yet
waitable. In the second, the leader is alive and the only other member
belongs to a different uid. The previous change blocked in
waitid(WEXITED|WNOWAIT) on any EPERM for our own child. In the second
case the leader never exits, so that wait would hang forever.

Now a non-blocking waitid probe first confirms the pid is our own
child; any other pid is never signalled and keeps the EPERM error. The
leader is then killed directly, which is always permitted on one's own
child and harmless on a zombie, and only then awaited without reaping,
so the wait has a bounded end.

Neither case has a deterministic reproduction: the first is a
scheduling window inside process exit, and the second needs a
cross-uid group member. Both follow from the killpg1() return rule.

* fix: accept a child that already leads its group on setpgid races

The forking test harnesses call lead_process_group() on both sides
of the fork, and the parent's setpgid(child, child) can lose the race.
Once the child has exec'd, setpgid() answers EACCES. Once it is
exiting, has become a session leader or has left our session, it
answers EPERM (xnu kern_prot.c setpgid()). macOS CI hits the EPERM
case as "put the test daemon in its own group: Operation not
permitted".

The child makes the group itself first, so either error now counts
as success when getpgid(child) == child. ESRCH from getpgid() means
the child ended in between, which is success as it already is for
setpgid(). Any other outcome is returned.

There are two deterministic tests. Both spawn an exec'd child, so the
parent's setpgid() is refused with EACCES:
- a child that set its own group before exec is accepted;
- a child left in our group is refused.
Inverting the getpgid() comparison fails both.

* refactor: delete the unused stream-compression reader and writer (#8260)

* fix: guard the sender exit flush and drop the goodbye finalizer

The goodbye handshake ran a finalizer between writing the sender's
NDX_DONE and reading the receiver's reply. It only called
finalize_compression(), which is a plain flush in production: no
production path builds a Compressed ServerWriter, since compression is
token-level as in upstream token.c. It also ran directly after the
flush that follows NDX_DONE, so it could never move a byte. Upstream
has no counterpart either. read_ndx_and_attrs() drains output in
perform_io() before it blocks, which is the existing flush, and
handle_goodbye_proto31_flushes_ndx_done_before_close already guards
it. Remove the finalizer parameter from the goodbye methods.

The orchestrator's exit flush is what upstream requires: main.c:1011
runs io_flush(FULL_FLUSH) after read_final_goodbye(), and
cleanup.c:194-195 flushes again on exit_cleanup(0). That includes the
empty-file-list early return at main.c:996-1001. Below protocol 30,
send_file_list() leaves the list end and the io_error word buffered,
and the multiplex writer has no flushing Drop. Without the flush the
client never receives them. A new run()-level test fails with an
empty wire when that flush is removed.

* fix: wait out an exiting leader on macOS killpg; portable flush fixture

kill_process_group on Apple treated EPERM as success only once waitid
already reported the leader as ended. A leader that has begun exiting
but is not yet waitable is skipped by XNU's killpg1() too, so the EPERM
can arrive first, and the test harness's Drop panicked with "stop the
test daemon N: Operation not permitted". This was seen on master's macOS
tracing row (daemon_pull_default_send_zc_byte_identical) and on the
iconv row here. EPERM for our own child now blocks in waitid until the
leader has ended, without reaping it.

The empty-file-list flush test relied on ENOTDIR from a path through a
regular file, which Windows reports as not-found, so no io_error was
raised there. Use a missing operand instead. The word is then 0, but the
list end plus four io_error bytes still have to reach the wire, and with
the early-return flush removed the wire carries no data at all.

* fix: SIGKILL the leader before awaiting it on a macOS killpg EPERM

XNU's killpg1() (bsd/kern/kern_sig.c) returns EPERM for a POSIX caller
whenever it signalled no member of the group. That covers two cases.
In the first, the leader is a zombie or is still exiting and not yet
waitable. In the second, the leader is alive and the only other member
belongs to a different uid. The previous change blocked in
waitid(WEXITED|WNOWAIT) on any EPERM for our own child. In the second
case the leader never exits, so that wait would hang forever.

Now a non-blocking waitid probe first confirms the pid is our own
child; any other pid is never signalled and keeps the EPERM error. The
leader is then killed directly, which is always permitted on one's own
child and harmless on a zombie, and only then awaited without reaping,
so the wait has a bounded end.

Neither case has a deterministic reproduction: the first is a
scheduling window inside process exit, and the second needs a
cross-uid group member. Both follow from the killpg1() return rule.

* refactor: delete the unused stream-compression reader and writer

Compression is token-level, as in upstream token.c, so no production
path ever wrapped the multiplexed stream in a compressor. Nothing
outside tests called ServerWriter::activate_compression*,
ServerReader::activate_compression, CompressedWriter or
CompressedReader. Delete them, their Compressed variants and match
arms, finalize_compression (flush_all_pending is now a flush that
tolerates a closed peer), and the tests that existed only to exercise
them.

ZstdStrategy::with_workers lost its only caller with CompressedWriter,
so it goes too; the strategy builds its encoder single-threaded, which
is what it already did for every caller.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant