Skip to content

Commit 8774cb4

Browse files
ronagBridgeAR
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 23a4d60 commit 8774cb4

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');
@@ -278,7 +278,8 @@ function closeFsStream(stream, cb, err) {
278278
}
279279

280280
ReadStream.prototype.close = function(cb) {
281-
this.destroy(null, cb);
281+
if (typeof cb === 'function') finished(this, cb);
282+
this.destroy();
282283
};
283284

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

0 commit comments

Comments
 (0)