Repository navigation
node:fs: do not pad copyFile/cp copies when copy_file_range fails partway #43398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
robobun
wants to merge
1
commit into
main
Choose a base branch
from
robobun/e17db816/cp-copy-file-range-fallback-count
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟣 pre-existing, not blocking: pre-existing: a caller of fs.cpSync on one file can get a spurious EINTR error on Linux, where the async twin retries. The sync copy_file_range match at node_fs.rs:8526 and :8570 has no
E::EINTR => continuearm, so EINTR falls to_ => return errand the copy aborts. The async copy_file_inner twin handles it at :5076 and :5115. Fix: handle EINTR the same way in both copy_single_file_sync loops (retry the call), so sync and async copies behave alike. Same pattern at 2 sites (node_fs.rs:8531, node_fs.rs:8575).A small fix can ride a push you are already making; otherwise a short reply is enough.
Extended reasoning...
The base branch behaves the same way; this diff edits the fallback arm of these two match blocks but leaves the EINTR gap. A user calls fs.cpSync(srcFile, destFile) with default options on Linux, which routes to copy_single_file_sync. copy_file_range is issued at node_fs.rs:8512 or :8556. The kernel's splice-based path in copy_file_range can return -ERESTARTSYS when a signal is pending before any bytes are copied in that call, which surfaces as EINTR when the handler was installed without SA_RESTART. The match at :8526-8542 (size 0 loop) and :8570-8586 (sized loop) lists only EXDEV/ENOSYS/EINVAL/EOPNOTSUPP, so EINTR hits
_ => return errat :8541 / :8585. cpSync throws an EINTR error and the destination is left partially written and ftruncated to the partialwroteby the scopeguard at :8484. The async twin in copy_file_inner hasE::EINTR => continueat :5076 and :5115, so fs.promises.cp / fs.copyFile retry and succeed on the same event. A correct fix adds the EINTR retry arm at both sync sites.Verification: pre-existing. Triggering condition: a signal whose handler was installed without SA_RESTART lands on the thread while copy_file_range is in the kernel's splice-based path with zero bytes progressed in that call (splice_from_pipe_next returns -ERESTARTSYS, surfaced as EINTR), during fs.cpSync/fs.cp of a single regular file on Linux. Mechanism verified in… | pre-existing — the base commit has the…