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: nodejs#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 25, 2020
1 parent b8c580b commit 03b07bb
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 @@ -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 03b07bb

Please sign in to comment.