@@ -144,7 +144,10 @@ function ReadableState(options, stream, isDuplex) {
144144 // Has it been destroyed
145145 this . destroyed = false ;
146146
147- // Indicates whether the stream has errored.
147+ // Indicates whether the stream has errored. When true no further
148+ // _read calls, 'data' or 'readable' events should occur. This is needed
149+ // since when autoDestroy is disabled we need a way to tell whether the
150+ // stream has failed.
148151 this . errored = false ;
149152
150153 // Indicates whether the stream has finished destroying.
@@ -258,7 +261,7 @@ function readableAddChunk(stream, chunk, encoding, addToFront) {
258261 addChunk ( stream , state , chunk , true ) ;
259262 } else if ( state . ended ) {
260263 errorOrDestroy ( stream , new ERR_STREAM_PUSH_AFTER_EOF ( ) ) ;
261- } else if ( state . destroyed ) {
264+ } else if ( state . destroyed || state . errored ) {
262265 return false ;
263266 } else {
264267 state . reading = false ;
@@ -453,9 +456,9 @@ Readable.prototype.read = function(n) {
453456 }
454457
455458 // However, if we've ended, then there's no point, if we're already
456- // reading, then it's unnecessary, and if we're destroyed, then it's
457- // not allowed.
458- if ( state . ended || state . reading || state . destroyed ) {
459+ // reading, then it's unnecessary, and if we're destroyed or errored,
460+ // then it's not allowed.
461+ if ( state . ended || state . reading || state . destroyed || state . errored ) {
459462 doRead = false ;
460463 debug ( 'reading or ended' , doRead ) ;
461464 } else if ( doRead ) {
@@ -553,7 +556,7 @@ function emitReadable(stream) {
553556function emitReadable_ ( stream ) {
554557 const state = stream . _readableState ;
555558 debug ( 'emitReadable_' , state . destroyed , state . length , state . ended ) ;
556- if ( ! state . destroyed && ( state . length || state . ended ) ) {
559+ if ( ! state . destroyed && ! state . errored && ( state . length || state . ended ) ) {
557560 stream . emit ( 'readable' ) ;
558561 state . emittedReadable = false ;
559562 }
0 commit comments