Skip to content
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
stream: don't emit after 'error'
  • Loading branch information
ronag committed Aug 17, 2019
commit c5cffa8b8c596b95675077944901ba82defdfb4a
7 changes: 4 additions & 3 deletions lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -607,10 +607,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) {
Expand Down
17 changes: 17 additions & 0 deletions test/parallel/test-stream2-writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}