diff --git a/lib/internal/streams/readable.js b/lib/internal/streams/readable.js index 919c527a2be6f8..f94d3bad7900a4 100644 --- a/lib/internal/streams/readable.js +++ b/lib/internal/streams/readable.js @@ -1238,6 +1238,9 @@ function nReadingNextTick(self) { // If the user uses them, then switch into old mode. Readable.prototype.resume = function() { const state = this._readableState; + if ((state[kState] & kDestroyed) !== 0) { + return this; + } if ((state[kState] & kFlowing) === 0) { debug('resume'); // We flow only if there is no one listening @@ -1278,6 +1281,9 @@ function resume_(stream, state) { Readable.prototype.pause = function() { const state = this._readableState; + if ((state[kState] & kDestroyed) !== 0) { + return this; + } debug('call pause'); if ((state[kState] & (kHasFlowing | kFlowing)) !== kHasFlowing) { debug('pause'); diff --git a/test/parallel/test-stream-destroy.js b/test/parallel/test-stream-destroy.js index 12706714aa7c8a..88bba6b8348894 100644 --- a/test/parallel/test-stream-destroy.js +++ b/test/parallel/test-stream-destroy.js @@ -118,3 +118,13 @@ const http = require('http'); req.end('asd'); })); } + +{ + // resume() and pause() should be no-ops on destroyed streams. + const r = new Readable({ read() {} }); + r.destroy(); + r.on('resume', common.mustNotCall()); + r.on('pause', common.mustNotCall()); + r.resume(); + r.pause(); +}