Skip to content

Commit

Permalink
fs: use finished over destroy w/ cb
Browse files Browse the repository at this point in the history
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 <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
  • Loading branch information
ronag authored and BridgeAR committed Apr 28, 2020
1 parent 23a4d60 commit 8774cb4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/internal/fs/streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const {
copyObject,
getOptions,
} = require('internal/fs/utils');
const { Readable, Writable } = require('stream');
const { Readable, Writable, finished } = require('stream');
const { toPathIfFileURL } = require('internal/url');
const kIoDone = Symbol('kIoDone');
const kIsPerformingIO = Symbol('kIsPerformingIO');
Expand Down Expand Up @@ -278,7 +278,8 @@ function closeFsStream(stream, cb, err) {
}

ReadStream.prototype.close = function(cb) {
this.destroy(null, cb);
if (typeof cb === 'function') finished(this, cb);
this.destroy();
};

ObjectDefineProperty(ReadStream.prototype, 'pending', {
Expand Down

0 comments on commit 8774cb4

Please sign in to comment.