Skip to content

Commit cd03f5b

Browse files
committed
stream: don't call _read after destroy()
1 parent f2e35ff commit cd03f5b

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

lib/_stream_readable.js

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

490-
// However, if we've ended, then there's no point, and if we're already
491-
// reading, then it's unnecessary.
492-
if (state.ended || state.reading) {
490+
// However, if we've ended, then there's no point, if we're already
491+
// reading, then it's unnecessary, and if we're destroyed, then it's
492+
// not allowed.
493+
if (state.ended || state.reading || state.destroyed) {
493494
doRead = false;
494495
debug('reading or ended', doRead);
495496
} 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+
}

0 commit comments

Comments
 (0)