Skip to content

Commit

Permalink
stream: don't emit 'finish' after 'error'
Browse files Browse the repository at this point in the history
PR-URL: #32275
Refs: #28710
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
ronag committed Mar 17, 2020
1 parent 40b559a commit 9b20b5d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,9 @@ 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 9b20b5d

Please sign in to comment.