@@ -144,7 +144,10 @@ function ReadableState(options, stream, isDuplex) {
144
144
// Has it been destroyed
145
145
this . destroyed = false ;
146
146
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.
148
151
this . errored = false ;
149
152
150
153
// Indicates whether the stream has finished destroying.
@@ -258,7 +261,7 @@ function readableAddChunk(stream, chunk, encoding, addToFront) {
258
261
addChunk ( stream , state , chunk , true ) ;
259
262
} else if ( state . ended ) {
260
263
errorOrDestroy ( stream , new ERR_STREAM_PUSH_AFTER_EOF ( ) ) ;
261
- } else if ( state . destroyed ) {
264
+ } else if ( state . destroyed || state . errored ) {
262
265
return false ;
263
266
} else {
264
267
state . reading = false ;
@@ -453,9 +456,9 @@ Readable.prototype.read = function(n) {
453
456
}
454
457
455
458
// 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 ) {
459
462
doRead = false ;
460
463
debug ( 'reading or ended' , doRead ) ;
461
464
} else if ( doRead ) {
@@ -553,7 +556,7 @@ function emitReadable(stream) {
553
556
function emitReadable_ ( stream ) {
554
557
const state = stream . _readableState ;
555
558
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 ) ) {
557
560
stream . emit ( 'readable' ) ;
558
561
state . emittedReadable = false ;
559
562
}
0 commit comments