Skip to content

Commit 03b07bb

Browse files
ronagtargos
authored andcommitted
fs: use finished over destroy w/ cb
destroy w/ is undocumented API which also will cause a race if the stream is already destroying and potentially invoking the callback too early and withou error. PR-URL: nodejs#32809 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com>
1 parent b8c580b commit 03b07bb

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/internal/fs/streams.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const {
2222
copyObject,
2323
getOptions,
2424
} = require('internal/fs/utils');
25-
const { Readable, Writable } = require('stream');
25+
const { Readable, Writable, finished } = require('stream');
2626
const { toPathIfFileURL } = require('internal/url');
2727
const kIoDone = Symbol('kIoDone');
2828
const kIsPerformingIO = Symbol('kIsPerformingIO');
@@ -266,7 +266,8 @@ function closeFsStream(stream, cb, err) {
266266
}
267267

268268
ReadStream.prototype.close = function(cb) {
269-
this.destroy(null, cb);
269+
if (typeof cb === 'function') finished(this, cb);
270+
this.destroy();
270271
};
271272

272273
ObjectDefineProperty(ReadStream.prototype, 'pending', {

0 commit comments

Comments
 (0)