Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 29b1966

Browse filesBrowse files
ronagaduh95
authored andcommitted
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 dd72df0 commit 29b1966
Copy full SHA for 29b1966

2 files changed

+16Lines changed: 16 additions & 0 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/streams/readable.js‎

Copy file name to clipboardExpand all lines: lib/internal/streams/readable.js
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,9 @@ function nReadingNextTick(self) {
12331233
// If the user uses them, then switch into old mode.
12341234
Readable.prototype.resume = function() {
12351235
const state = this._readableState;
1236+
if ((state[kState] & kDestroyed) !== 0) {
1237+
return this;
1238+
}
12361239
if ((state[kState] & kFlowing) === 0) {
12371240
debug('resume');
12381241
// We flow only if there is no one listening
@@ -1273,6 +1276,9 @@ function resume_(stream, state) {
12731276

12741277
Readable.prototype.pause = function() {
12751278
const state = this._readableState;
1279+
if ((state[kState] & kDestroyed) !== 0) {
1280+
return this;
1281+
}
12761282
debug('call pause');
12771283
if ((state[kState] & (kHasFlowing | kFlowing)) !== kHasFlowing) {
12781284
debug('pause');
Collapse file

‎test/parallel/test-stream-destroy.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-stream-destroy.js
+10Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.