mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
stream: don't emit prefinish after error or close
PR-URL: https://github.com/nodejs/node/pull/39332 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
5960f16713
commit
7a7ba82234
@ -654,7 +654,9 @@ function needFinish(state) {
|
||||
!state.errored &&
|
||||
state.buffered.length === 0 &&
|
||||
!state.finished &&
|
||||
!state.writing);
|
||||
!state.writing &&
|
||||
!state.errorEmitted &&
|
||||
!state.closeEmitted);
|
||||
}
|
||||
|
||||
function callFinal(stream, state) {
|
||||
@ -685,7 +687,7 @@ function callFinal(stream, state) {
|
||||
then.call(
|
||||
result,
|
||||
function() {
|
||||
if (state.prefinished)
|
||||
if (state.prefinished || !needFinish(state))
|
||||
return;
|
||||
state.prefinish = true;
|
||||
process.nextTick(() => stream.emit('prefinish'));
|
||||
@ -735,10 +737,6 @@ function finishMaybe(stream, state, sync) {
|
||||
|
||||
function finish(stream, state) {
|
||||
state.pendingcb--;
|
||||
// TODO (ronag): Unify with needFinish.
|
||||
if (state.errorEmitted || state.closeEmitted)
|
||||
return;
|
||||
|
||||
state.finished = true;
|
||||
|
||||
const onfinishCallbacks = state[kOnFinished].splice(0);
|
||||
|
21
test/parallel/test-stream-writable-final-destroy.js
Normal file
21
test/parallel/test-stream-writable-final-destroy.js
Normal file
@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
|
||||
const { Writable } = require('stream');
|
||||
|
||||
{
|
||||
const w = new Writable({
|
||||
write(chunk, encoding, callback) {
|
||||
callback(null);
|
||||
},
|
||||
final(callback) {
|
||||
queueMicrotask(callback);
|
||||
}
|
||||
});
|
||||
w.end();
|
||||
w.destroy();
|
||||
|
||||
w.on('prefinish', common.mustNotCall());
|
||||
w.on('finish', common.mustNotCall());
|
||||
w.on('close', common.mustCall());
|
||||
}
|
Loading…
Reference in New Issue
Block a user