Skip to content

Commit b2faef5

Browse files
Nitzan UzielyLinkgoron
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
1 parent a142842 commit b2faef5

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/fs.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,11 @@ function readFile(path, options, callback) {
342342
return;
343343
}
344344

345+
if (options.signal?.aborted) {
346+
callback(lazyDOMException('The operation was aborted', 'AbortError'));
347+
return;
348+
}
349+
345350
const flagsNumber = stringToFlags(options.flag);
346351
path = getValidatedPath(path);
347352

@@ -1452,7 +1457,13 @@ function lutimesSync(path, atime, mtime) {
14521457

14531458
function writeAll(fd, isUserFd, buffer, offset, length, signal, callback) {
14541459
if (signal?.aborted) {
1455-
callback(lazyDOMException('The operation was aborted', 'AbortError'));
1460+
if (isUserFd) {
1461+
callback(lazyDOMException('The operation was aborted', 'AbortError'));
1462+
} else {
1463+
fs.close(fd, function() {
1464+
callback(lazyDOMException('The operation was aborted', 'AbortError'));
1465+
});
1466+
}
14561467
return;
14571468
}
14581469
// write(fd, buffer, offset, length, position, callback)

0 commit comments

Comments
 (0)