Skip to content

Commit 9b20b5d

Browse files
committed
stream: don't emit 'finish' after 'error'
PR-URL: #32275 Refs: #28710 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 40b559a commit 9b20b5d

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

lib/_stream_writable.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,9 @@ function finishMaybe(stream, state, sync) {
666666

667667
function finish(stream, state) {
668668
state.pendingcb--;
669+
if (state.errorEmitted)
670+
return;
671+
669672
state.finished = true;
670673
stream.emit('finish');
671674

test/parallel/test-stream-writable-write-writev-finish.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ const stream = require('stream');
132132
process.nextTick(cb);
133133
};
134134
w.on('error', common.mustCall());
135+
w.on('finish', common.mustNotCall());
135136
w.on('prefinish', () => {
136137
w.write("shouldn't write in prefinish listener");
137138
});

0 commit comments

Comments
 (0)