Skip to content

Commit 4dc18ef

Browse files
authored
stream: noop pause/resume on destroyed streams
Signed-off-by: Robert Nagy <ronagy@icloud.com> PR-URL: #62557 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
1 parent f1ed8d6 commit 4dc18ef

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
@@ -1242,6 +1242,9 @@ function nReadingNextTick(self) {
12421242
// If the user uses them, then switch into old mode.
12431243
Readable.prototype.resume = function() {
12441244
const state = this._readableState;
1245+
if ((state[kState] & kDestroyed) !== 0) {
1246+
return this;
1247+
}
12451248
if ((state[kState] & kFlowing) === 0) {
12461249
debug('resume');
12471250
// We flow only if there is no one listening
@@ -1282,6 +1285,9 @@ function resume_(stream, state) {
12821285

12831286
Readable.prototype.pause = function() {
12841287
const state = this._readableState;
1288+
if ((state[kState] & kDestroyed) !== 0) {
1289+
return this;
1290+
}
12851291
debug('call pause');
12861292
if ((state[kState] & (kHasFlowing | kFlowing)) !== kHasFlowing) {
12871293
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)