Skip to content
Open
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/iter/broadcast.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ class BroadcastWriter {

if (policy === 'strict') {
if (this.#pendingWrites.length >= hwm) {
throw new ERR_INVALID_STATE.TypeError(
throw new ERR_INVALID_STATE.RangeError(
'Backpressure violation: too many pending writes. ' +
'Await each write() call to respect backpressure.');
}
Expand Down
23 changes: 23 additions & 0 deletions test/parallel/test-stream-iter-broadcast-backpressure.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,28 @@ async function testBlockBackpressureContent() {
assert.strictEqual(done.done, true);
}

async function testStrictBackpressureOverflow() {
const { writer } = broadcast({
highWaterMark: 1,
backpressure: 'strict',
});

await writer.write('a');
const pending = writer.write('b');

await assert.rejects(writer.write('c'), {
name: 'RangeError',
code: 'ERR_INVALID_STATE',
});

writer.fail();
await assert.rejects(pending, {
name: 'TypeError',
code: 'ERR_INVALID_STATE',
message: 'Invalid state: Failed',
});
}

// Writev async path
async function testWritevAsync() {
const { writer, broadcast: bc } = broadcast({ highWaterMark: 10 });
Expand Down Expand Up @@ -133,6 +155,7 @@ Promise.all([
testDropNewest(),
testBlockBackpressure(),
testBlockBackpressureContent(),
testStrictBackpressureOverflow(),
testWritevAsync(),
testEndSyncReturnValue(),
]).then(common.mustCall());
Loading