diff --git a/lib/fs.js b/lib/fs.js index 3d6dc93354b71c..a19f84b4f404bd 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -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)