Repository navigation
Conversation
When SIGUSR1 aborts an --inplace/--append transfer, _exit_cleanup() runs inside the handler and flushes the receiver's write buffer. If the handler interrupted flush_write_file() after write() returned but before wf_writeBufCnt was updated, the same bytes are written a second time, and with --append the file keeps a duplicated 256 KiB region. Skip that flush when called from a signal handler. A SIGINT, SIGTERM or SIGHUP that reaches the receiver itself still exits from normal code through got_kill_signal, so its flush is unaffected.
Hold the receiver right after its first write() to the destination, with every signal pending, send it SIGUSR1 and check that the destination is still a prefix of the source. This fails without the previous commit. The hold is an LD_PRELOAD shim, so the test is Linux-only and is expected to skip on macOS and Cygwin.
peterochek
force-pushed
the
cleanup-no-flush-in-signal-handler
branch
from
October 13, 2026 11:23
78e0e9b to
a9b52df
Compare
steadytao
approved these changes
Oct 13, 2026
steadytao
left a comment
Member
There was a problem hiding this comment.
Pretty minimal and good fix. Thank you. LGTM.
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.
Fixes #1128.
If rsync is stopped in the middle of an
--appendor--inplacetransfer, the receiver can write its last 256 KiB buffer twice. With--appendthe duplicate stays in the file for good. #1128 has the full story and a reproduction script.The change
When a transfer aborts, the receiver gets SIGUSR1 and runs its exit cleanup inside the signal handler. The handler may have interrupted
flush_write_file()right after awrite()returned, before the buffer's byte count was updated, so flushing the buffer again from there can write the same data twice.This PR skips that flush when the cleanup runs from a signal handler. The same function already checks
called_from_signal_handlerfor a similar reason: to call_exit()instead ofexit().Effect on behaviour
got_kill_signal, and that path still flushes.If you'd rather keep the flush whenever it is safe, a guard inside
flush_write_file()that skips only an interrupted flush also works, and I can switch the PR to that.Tests
New
testsuite/append-abort-mid-write_test.py:--appendand--inplace.--protocol=29and--protocol=30and in a clang ASan+UBSan build.source-change-size-continues, it builds its shim at run time and is Linux-only, so it is added to the macOS and Cygwin skip lists.make check(unprivileged build without ACL support): 268 passed, 99 skipped. The per-test results match master apart from the new test.