stream: do not emit after 'error'
Do not emit 'prefinish' or 'finish' event after an error. PR-URL: https://github.com/nodejs/node/pull/28708 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
parent
4e782c9deb
commit
188896ea3e
@ -617,10 +617,11 @@ function callFinal(stream, state) {
|
||||
state.pendingcb--;
|
||||
if (err) {
|
||||
errorOrDestroy(stream, err);
|
||||
} else {
|
||||
state.prefinished = true;
|
||||
stream.emit('prefinish');
|
||||
finishMaybe(stream, state);
|
||||
}
|
||||
state.prefinished = true;
|
||||
stream.emit('prefinish');
|
||||
finishMaybe(stream, state);
|
||||
});
|
||||
}
|
||||
function prefinish(stream, state) {
|
||||
|
@ -441,3 +441,20 @@ const helloWorldBuffer = Buffer.from('hello world');
|
||||
w.write('hello');
|
||||
w.destroy(new Error());
|
||||
}
|
||||
|
||||
{
|
||||
// Verify that finish is not emitted after error
|
||||
const w = new W();
|
||||
|
||||
w._final = common.mustCall(function(cb) {
|
||||
cb(new Error());
|
||||
});
|
||||
w._write = function(chunk, e, cb) {
|
||||
process.nextTick(cb);
|
||||
};
|
||||
w.on('error', common.mustCall());
|
||||
w.on('prefinish', common.mustNotCall());
|
||||
w.on('finish', common.mustNotCall());
|
||||
w.write(Buffer.allocUnsafe(1));
|
||||
w.end(Buffer.allocUnsafe(0));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user