Skip to content

Commit 142dc31

Browse files
committed
stream: pause/resume on destroyed streams should be noop
1 parent e0d2e1c commit 142dc31

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/internal/streams/readable.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,9 @@ function nReadingNextTick(self) {
12381238
// If the user uses them, then switch into old mode.
12391239
Readable.prototype.resume = function() {
12401240
const state = this._readableState;
1241+
if ((state[kState] & kDestroyed) !== 0) {
1242+
return this;
1243+
}
12411244
if ((state[kState] & kFlowing) === 0) {
12421245
debug('resume');
12431246
// We flow only if there is no one listening
@@ -1278,6 +1281,9 @@ function resume_(stream, state) {
12781281

12791282
Readable.prototype.pause = function() {
12801283
const state = this._readableState;
1284+
if ((state[kState] & kDestroyed) !== 0) {
1285+
return this;
1286+
}
12811287
debug('call pause');
12821288
if ((state[kState] & (kHasFlowing | kFlowing)) !== kHasFlowing) {
12831289
debug('pause');

test/parallel/test-stream-destroy.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,13 @@ const http = require('http');
118118
req.end('asd');
119119
}));
120120
}
121+
122+
{
123+
// resume() and pause() should be no-ops on destroyed streams.
124+
const r = new Readable({ read() {} });
125+
r.destroy();
126+
r.on('resume', common.mustNotCall());
127+
r.on('pause', common.mustNotCall());
128+
r.resume();
129+
r.pause();
130+
}

0 commit comments

Comments
 (0)