Skip to content

Commit ec390b6

Browse files
ronagTrott
authored andcommitted
stream: do not call _read() after destroy()
PR-URL: #29491 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent 8709a40 commit ec390b6

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

lib/_stream_readable.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,9 +490,10 @@ Readable.prototype.read = function(n) {
490490
debug('length less than watermark', doRead);
491491
}
492492

493-
// However, if we've ended, then there's no point, and if we're already
494-
// reading, then it's unnecessary.
495-
if (state.ended || state.reading) {
493+
// However, if we've ended, then there's no point, if we're already
494+
// reading, then it's unnecessary, and if we're destroyed, then it's
495+
// not allowed.
496+
if (state.ended || state.reading || state.destroyed) {
496497
doRead = false;
497498
debug('reading or ended', doRead);
498499
} else if (doRead) {

lib/internal/fs/streams.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,6 @@ ReadStream.prototype._read = function(n) {
137137
});
138138
}
139139

140-
if (this.destroyed)
141-
return;
142-
143140
if (!pool || pool.length - pool.used < kMinPoolSpace) {
144141
// Discard the old pool.
145142
allocNewPool(this.readableHighWaterMark);

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,12 @@ const assert = require('assert');
189189
read.push('hi');
190190
read.on('data', common.mustNotCall());
191191
}
192+
193+
{
194+
const read = new Readable({
195+
read: common.mustNotCall(function() {})
196+
});
197+
read.destroy();
198+
assert.strictEqual(read.destroyed, true);
199+
read.read();
200+
}

test/parallel/test-wrap-js-stream-exceptions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ process.once('uncaughtException', common.mustCall((err) => {
1010
}));
1111

1212
const socket = new JSStreamWrap(new Duplex({
13-
read: common.mustCall(),
13+
read: common.mustNotCall(),
1414
write: common.mustCall((buffer, data, cb) => {
1515
throw new Error('exception!');
1616
})

0 commit comments

Comments
 (0)