Skip to content

Commit

Permalink
stream: don't emit 'finish' after 'error'
Browse files Browse the repository at this point in the history
Backport-PR-URL: #32372
PR-URL: #32275
Refs: #28710
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Backport-PR-URL: #32372
  • Loading branch information
ronag authored and MylesBorins committed Mar 24, 2020
1 parent 471a5d8 commit 23ba088
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,8 @@ function finishMaybe(stream, state) {
if (need) {
prefinish(stream, state);
if (state.pendingcb === 0) {
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 23ba088

Please sign in to comment.