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 authored and Linkgoron committed Feb 20, 2021
1 parent a142842 commit b2faef5
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 @@ -1452,7 +1457,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 b2faef5

Please sign in to comment.