Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/internal/streams/readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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');
Expand Down
10 changes: 10 additions & 0 deletions test/parallel/test-stream-destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Loading