Skip to content

Commit

Permalink
stream: don't emit 'finish' after 'error'
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Mar 15, 2020
1 parent 4fedb70 commit 48e7a2e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,10 @@ function finishMaybe(stream, state, sync) {

function finish(stream, state) {
state.pendingcb--;
if (state.errorEmitted) {
return;
}

state.finished = true;
stream.emit('finish');

Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-stream-writable-write-writev-finish.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ const stream = require('stream');
process.nextTick(cb);
};
w.on('error', common.mustCall());
w.on('finish', common.mustNotCall());
w.on('prefinish', () => {
w.write("shouldn't write in prefinish listener");
});
Expand Down

0 comments on commit 48e7a2e

Please sign in to comment.