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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Nitzan Uziely authored and Michaël Zasso committed 2021-05-01 12:25:15 +02:00
1 parent 52b3b54c14
commit f2279f856e
1 file changed
+12 -1
+12 -1
View File
@@ -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);
@@ -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)