Skip to content

Commit 322bc6f

Browse files
ronagBridgeAR
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 13d173f commit 322bc6f

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

lib/_stream_readable.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -473,9 +473,10 @@ Readable.prototype.read = function(n) {
473473
debug('length less than watermark', doRead);
474474
}
475475

476-
// However, if we've ended, then there's no point, and if we're already
477-
// reading, then it's unnecessary.
478-
if (state.ended || state.reading) {
476+
// However, if we've ended, then there's no point, if we're already
477+
// reading, then it's unnecessary, and if we're destroyed, then it's
478+
// not allowed.
479+
if (state.ended || state.reading || state.destroyed) {
479480
doRead = false;
480481
debug('reading or ended', doRead);
481482
} else if (doRead) {

lib/internal/fs/streams.js

-3
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

+9
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

+1-1
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)