Skip to content

Commit f2279f8

Browse files
Nitzan Uzielytargos
Nitzan Uziely
authored andcommitted
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: #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>
1 parent 52b3b54 commit f2279f8

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/fs.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,11 @@ function readFile(path, options, callback) {
334334
return;
335335
}
336336

337+
if (options.signal?.aborted) {
338+
callback(lazyDOMException('The operation was aborted', 'AbortError'));
339+
return;
340+
}
341+
337342
const flagsNumber = stringToFlags(options.flag);
338343
path = getValidatedPath(path);
339344

@@ -1440,7 +1445,13 @@ function lutimesSync(path, atime, mtime) {
14401445

14411446
function writeAll(fd, isUserFd, buffer, offset, length, signal, callback) {
14421447
if (signal?.aborted) {
1443-
callback(lazyDOMException('The operation was aborted', 'AbortError'));
1448+
if (isUserFd) {
1449+
callback(lazyDOMException('The operation was aborted', 'AbortError'));
1450+
} else {
1451+
fs.close(fd, function() {
1452+
callback(lazyDOMException('The operation was aborted', 'AbortError'));
1453+
});
1454+
}
14441455
return;
14451456
}
14461457
// write(fd, buffer, offset, length, position, callback)

0 commit comments

Comments
 (0)