Skip to content

Commit ed4fbef

Browse files
ronagMylesBorins
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: #32809 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Denys Otrishko <[email protected]>
1 parent 4bb29ed commit ed4fbef

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/internal/fs/streams.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const {
2323
copyObject,
2424
getOptions,
2525
} = require('internal/fs/utils');
26-
const { Readable, Writable } = require('stream');
26+
const { Readable, Writable, finished } = require('stream');
2727
const { toPathIfFileURL } = require('internal/url');
2828
const kIoDone = Symbol('kIoDone');
2929
const kIsPerformingIO = Symbol('kIsPerformingIO');
@@ -273,7 +273,8 @@ function closeFsStream(stream, cb, err) {
273273
}
274274

275275
ReadStream.prototype.close = function(cb) {
276-
this.destroy(null, cb);
276+
if (typeof cb === 'function') finished(this, cb);
277+
this.destroy();
277278
};
278279

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

0 commit comments

Comments
 (0)