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
  • Loading branch information
Nitzan Uziely committed Feb 16, 2021
1 parent 88d9268 commit 6e6229e
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 @@ -338,6 +338,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 @@ -1448,7 +1453,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 6e6229e

Please sign in to comment.