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 targos committed Apr 28, 2020
1 parent 50130f0 commit 6d6bb2a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/internal/fs/streams.js
Expand Up @@ -22,7 +22,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 @@ -266,7 +266,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 6d6bb2a

Please sign in to comment.