fs: close file streams with fd 0

Signed-off-by: greenhead <greenheadhq@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66131
Fixes: https://github.com/nodejs/node/issues/57905
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
greenhead authored and Antoine du Hamel committed 2026-11-11 17:27:34 +01:00
1 parent 462946a5fa
commit 2c26192314
2 files changed
+16 -2

No files matched your search

+1 -1
View File
@@ -123,7 +123,7 @@ const FileHandleOperations = (handle) => {
};
function close(stream, err, cb) {
if (!stream.fd) {
if (stream.fd == null) {
cb(err);
} else if (stream.flush) {
stream[kFs].fsync(stream.fd, (flushErr) => {
+15 -1
View File
@@ -1,6 +1,6 @@
'use strict';
require('../common');
const common = require('../common');
const fixtures = require('../common/fixtures');
const fs = require('fs');
const assert = require('assert');
@@ -70,3 +70,17 @@ const originalFs = { fs };
);
});
}
for (const createStream of [fs.createReadStream, fs.createWriteStream]) {
const stream = createStream(null, {
fd: 0,
fs: {
...fs,
close: common.mustCall((fd, callback) => {
assert.strictEqual(fd, 0);
callback(null);
}),
},
});
stream.destroy();
}