diff options
author | Mathias Buus <mathiasbuus@gmail.com> | 2018-01-29 19:32:34 +0100 |
---|---|---|
committer | Matteo Collina <hello@matteocollina.com> | 2018-03-06 13:31:56 +0100 |
commit | 5e3f51648ed5de36b01d53bde13fb6fb7b965667 (patch) | |
tree | a134fb92b8b846e195ea3f960131fcc9147533e6 /lib/_stream_readable.js | |
parent | acac0f852a02c2b129adbc51e0bd8bd482d791af (diff) | |
download | android-node-v8-5e3f51648ed5de36b01d53bde13fb6fb7b965667.tar.gz android-node-v8-5e3f51648ed5de36b01d53bde13fb6fb7b965667.tar.bz2 android-node-v8-5e3f51648ed5de36b01d53bde13fb6fb7b965667.zip |
stream: updated streams error handling
This improves error handling for streams in a few ways.
1. It ensures that no user defined methods (_read, _write, ...) are run
after .destroy has been called.
2. It introduces an explicit error to tell the user if they are write to
write, etc to the stream after it has been destroyed.
3. It makes streams always emit close as the last thing after they have
been destroyed
4. Changes the default _destroy to not gracefully end streams.
It also updates net, http2, zlib and fs to the new error handling.
PR-URL: https://github.com/nodejs/node/pull/18438
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'lib/_stream_readable.js')
-rw-r--r-- | lib/_stream_readable.js | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index ba231ccda9..5781dfd471 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -106,6 +106,9 @@ function ReadableState(options, stream) { this.readableListening = false; this.resumeScheduled = false; + // Should close be emitted on destroy. Defaults to true. + this.emitClose = options.emitClose !== false; + // has it been destroyed this.destroyed = false; @@ -177,7 +180,6 @@ Object.defineProperty(Readable.prototype, 'destroyed', { Readable.prototype.destroy = destroyImpl.destroy; Readable.prototype._undestroy = destroyImpl.undestroy; Readable.prototype._destroy = function(err, cb) { - this.push(null); cb(err); }; @@ -236,6 +238,8 @@ function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) { addChunk(stream, state, chunk, true); } else if (state.ended) { stream.emit('error', new errors.Error('ERR_STREAM_PUSH_AFTER_EOF')); + } else if (state.destroyed) { + return false; } else { state.reading = false; if (state.decoder && !encoding) { |