Skip to content

Commit 23ba088

Browse files
ronagMylesBorins
authored andcommitted
stream: don't emit 'finish' after 'error'
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
1 parent 471a5d8 commit 23ba088

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

lib/_stream_writable.js

+2
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,8 @@ function finishMaybe(stream, state) {
647647
if (need) {
648648
prefinish(stream, state);
649649
if (state.pendingcb === 0) {
650+
if (state.errorEmitted)
651+
return;
650652
state.finished = true;
651653
stream.emit('finish');
652654

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

+1
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)