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 <ronagy@icloud.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
  • Loading branch information
Nitzan Uziely authored and targos committed May 1, 2021
1 parent 52b3b54 commit f2279f8
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/fs.js
Expand Up @@ -334,6 +334,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 @@ -1440,7 +1445,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 f2279f8

Please sign in to comment.