Skip to content

Commit 36dd044

Browse files
authored
fs: close file streams with fd 0
Signed-off-by: greenhead <greenheadhq@gmail.com> PR-URL: #66131 Fixes: #57905 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 26bcd1e commit 36dd044

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

‎lib/internal/fs/streams.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ const FileHandleOperations = (handle) => {
122122
};
123123

124124
function close(stream, err, cb) {
125-
if (!stream.fd) {
125+
if (stream.fd == null) {
126126
cb(err);
127127
} else if (stream.flush) {
128128
stream[kFs].fsync(stream.fd, (flushErr) => {

‎test/parallel/test-fs-stream-fs-options.js‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
require('../common');
3+
const common = require('../common');
44
const fixtures = require('../common/fixtures');
55
const fs = require('fs');
66
const assert = require('assert');
@@ -70,3 +70,17 @@ const originalFs = { fs };
7070
);
7171
});
7272
}
73+
74+
for (const createStream of [fs.createReadStream, fs.createWriteStream]) {
75+
const stream = createStream(null, {
76+
fd: 0,
77+
fs: {
78+
...fs,
79+
close: common.mustCall((fd, callback) => {
80+
assert.strictEqual(fd, 0);
81+
callback(null);
82+
}),
83+
},
84+
});
85+
stream.destroy();
86+
}

0 commit comments

Comments
 (0)