Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream: add new when constructing ERR_MULTIPLE_CALLBACK #52110

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/internal/streams/writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ function needFinish(state) {

function onFinish(stream, state, err) {
if ((state[kState] & kPrefinished) !== 0) {
errorOrDestroy(stream, err ?? ERR_MULTIPLE_CALLBACK());
errorOrDestroy(stream, err ?? new ERR_MULTIPLE_CALLBACK());
return;
}
state.pendingcb--;
Expand Down
25 changes: 25 additions & 0 deletions test/parallel/test-stream-err-multiple-callback-construction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';
const common = require('../common');
const stream = require('stream');
haze marked this conversation as resolved.
Show resolved Hide resolved
const assert = require('assert');

class TestWritable extends stream.Writable {
_write(_chunk, _encoding, callback) {
callback();
}

_final(callback) {
process.nextTick(callback);
process.nextTick(callback);
}
}

const writable = new TestWritable();

writable.on('finish', common.mustCall());
writable.on('error', common.mustCall((error) => {
assert.strictEqual(error.message, 'Callback called multiple times');
}));

writable.write('some data');
writable.end();
Loading