stream: noop pause/resume on destroyed streams

Signed-off-by: Robert Nagy <ronagy@icloud.com>
PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Robert Nagy authored and GitHub committed 2026-04-10 11:13:34 +02:00
1 parent f1ed8d63b5
commit 4dc18ef29d
2 files changed
+16

No files matched your search

+6
View File
@@ -1242,6 +1242,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
@@ -1282,6 +1285,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');
+10
View File
@@ -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();
}