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 <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Denys Otrishko <[email protected]>
  • Loading branch information
ronag committed Apr 15, 2020
1 parent 3f5142d commit a495a5e
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 @@ -273,7 +273,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 a495a5e

Please sign in to comment.