stream: do not call _read() after destroy()
PR-URL: https://github.com/nodejs/node/pull/29491 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
This commit is contained in:
parent
8709a408d2
commit
ec390b63a1
@ -490,9 +490,10 @@ Readable.prototype.read = function(n) {
|
||||
debug('length less than watermark', doRead);
|
||||
}
|
||||
|
||||
// However, if we've ended, then there's no point, and if we're already
|
||||
// reading, then it's unnecessary.
|
||||
if (state.ended || state.reading) {
|
||||
// However, if we've ended, then there's no point, if we're already
|
||||
// reading, then it's unnecessary, and if we're destroyed, then it's
|
||||
// not allowed.
|
||||
if (state.ended || state.reading || state.destroyed) {
|
||||
doRead = false;
|
||||
debug('reading or ended', doRead);
|
||||
} else if (doRead) {
|
||||
|
@ -137,9 +137,6 @@ ReadStream.prototype._read = function(n) {
|
||||
});
|
||||
}
|
||||
|
||||
if (this.destroyed)
|
||||
return;
|
||||
|
||||
if (!pool || pool.length - pool.used < kMinPoolSpace) {
|
||||
// Discard the old pool.
|
||||
allocNewPool(this.readableHighWaterMark);
|
||||
|
@ -189,3 +189,12 @@ const assert = require('assert');
|
||||
read.push('hi');
|
||||
read.on('data', common.mustNotCall());
|
||||
}
|
||||
|
||||
{
|
||||
const read = new Readable({
|
||||
read: common.mustNotCall(function() {})
|
||||
});
|
||||
read.destroy();
|
||||
assert.strictEqual(read.destroyed, true);
|
||||
read.read();
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ process.once('uncaughtException', common.mustCall((err) => {
|
||||
}));
|
||||
|
||||
const socket = new JSStreamWrap(new Duplex({
|
||||
read: common.mustCall(),
|
||||
read: common.mustNotCall(),
|
||||
write: common.mustCall((buffer, data, cb) => {
|
||||
throw new Error('exception!');
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user