Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[x] stream: don't call _read after destroy() #29485

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,11 @@ Readable.prototype.read = function(n) {
n = parseInt(n, 10);
}
const state = this._readableState;

if (state.destroyed) {
return;
}

const nOrig = n;

// If we're asking for more than the current hwm, then raise the hwm.
Expand Down Expand Up @@ -643,7 +648,7 @@ function maybeReadMore_(stream, state) {
// called push() with new data. In this case we skip performing more
// read()s. The execution ends in this method again after the _read() ends
// up calling push() with more data.
while (!state.reading && !state.ended &&
while (!state.reading && !state.ended && !state.destroyed &&
(state.length < state.highWaterMark ||
(state.flowing && state.length === 0))) {
const len = state.length;
Expand Down Expand Up @@ -976,6 +981,12 @@ function resume(stream, state) {

function resume_(stream, state) {
debug('resume', state.reading);

if (state.destroyed) {
state.resumeScheduled = false;
return;
}

if (!state.reading) {
stream.read(0);
}
Expand Down
9 changes: 9 additions & 0 deletions test/parallel/test-stream-readable-destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
29 changes: 0 additions & 29 deletions test/parallel/test-stream-transform-destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,35 +91,6 @@ const assert = require('assert');
transform.destroy();
}

{
const transform = new Transform({
transform(chunk, enc, cb) {}
});
transform.resume();

transform._destroy = common.mustCall(function(err, cb) {
assert.strictEqual(err, null);
process.nextTick(() => {
this.push(null);
this.end();
cb();
});
}, 1);

const fail = common.mustNotCall('no event');

transform.on('finish', fail);
transform.on('end', fail);
transform.on('close', common.mustCall());

transform.destroy();

transform.removeListener('end', fail);
transform.removeListener('finish', fail);
transform.on('end', common.mustCall());
transform.on('finish', common.mustCall());
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test doesn't seem to be testing correct behaviour. We should not have either 'end' nor 'finish' after destroy().


{
const transform = new Transform({
transform(chunk, enc, cb) {}
Expand Down