summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Nagy <ronagy@icloud.com>2020-04-13 11:18:56 +0200
committerRobert Nagy <ronagy@icloud.com>2020-04-15 14:39:20 +0200
commita495a5ea4ac740f33bf716b2fb8f1fe8ba8f4bad (patch)
treea4816b3240c31ea6fb7c2aed46bb490f23b01ea4
parent3f5142daa82e91af05fa006116ea69ca888f6bc0 (diff)
downloadnode-new-a495a5ea4ac740f33bf716b2fb8f1fe8ba8f4bad.tar.gz
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: https://github.com/nodejs/node/pull/32809 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com>
-rw-r--r--lib/internal/fs/streams.js5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/internal/fs/streams.js b/lib/internal/fs/streams.js
index a76a8f6895..2f5f8948ee 100644
--- a/lib/internal/fs/streams.js
+++ b/lib/internal/fs/streams.js
@@ -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');
@@ -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', {