Skip to content

Commit

Permalink
fs: fix writeFile signal does not close file
Browse files Browse the repository at this point in the history
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 targos committed Feb 28, 2021
1 parent e8b1e2c commit c0cdb83
Showing 1 changed file with 12 additions and 1 deletion.
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'));
});
}
return;
}
// write(fd, buffer, offset, length, position, callback)
Expand Down

0 comments on commit c0cdb83

Please sign in to comment.