Skip to content
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

fs: fix writeFile AbortSignal does not close file #37402

Merged
merged 1 commit into from
Feb 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fs: fix writeFile signal does not close file
Fix an issue where the writeFile does not close the file
when the signal is aborted.

PR-URL: #37402
Reviewed-By: Robert Nagy <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
  • Loading branch information
Nitzan Uziely authored and aduh95 committed Feb 26, 2021
commit 503d6ccdefa648d474b8121359a9a8b84ad8dd2c
13 changes: 12 additions & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,11 @@ function readFile(path, options, callback) {
return;
}

if (options.signal?.aborted) {
callback(lazyDOMException('The operation was aborted', 'AbortError'));
return;
}

const flagsNumber = stringToFlags(options.flag);
path = getValidatedPath(path);

Expand Down Expand Up @@ -1453,7 +1458,13 @@ function lutimesSync(path, atime, mtime) {

function writeAll(fd, isUserFd, buffer, offset, length, signal, callback) {
if (signal?.aborted) {
callback(lazyDOMException('The operation was aborted', 'AbortError'));
if (isUserFd) {
callback(lazyDOMException('The operation was aborted', 'AbortError'));
} else {
fs.close(fd, function() {
callback(lazyDOMException('The operation was aborted', 'AbortError'));
});
Linkgoron marked this conversation as resolved.
Show resolved Hide resolved
}
Linkgoron marked this conversation as resolved.
Show resolved Hide resolved
return;
}
// write(fd, buffer, offset, length, position, callback)
Expand Down