Skip to content

Commit e37419d

Browse files
committed
stream: use RangeError for broadcast overflow
Reject strict-backpressure writes with a RangeError when the broadcast pending writes queue is full. Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
1 parent 6eff679 commit e37419d

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

lib/internal/streams/iter/broadcast.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ class BroadcastWriter {
582582

583583
if (policy === 'strict') {
584584
if (this.#pendingWrites.length >= hwm) {
585-
throw new ERR_INVALID_STATE.TypeError(
585+
throw new ERR_INVALID_STATE.RangeError(
586586
'Backpressure violation: too many pending writes. ' +
587587
'Await each write() call to respect backpressure.');
588588
}

test/parallel/test-stream-iter-broadcast-backpressure.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,28 @@ async function testBlockBackpressureContent() {
105105
assert.strictEqual(done.done, true);
106106
}
107107

108+
async function testStrictBackpressureOverflow() {
109+
const { writer } = broadcast({
110+
highWaterMark: 1,
111+
backpressure: 'strict',
112+
});
113+
114+
await writer.write('a');
115+
const pending = writer.write('b');
116+
117+
await assert.rejects(writer.write('c'), {
118+
name: 'RangeError',
119+
code: 'ERR_INVALID_STATE',
120+
});
121+
122+
writer.fail();
123+
await assert.rejects(pending, {
124+
name: 'TypeError',
125+
code: 'ERR_INVALID_STATE',
126+
message: 'Invalid state: Failed',
127+
});
128+
}
129+
108130
// Writev async path
109131
async function testWritevAsync() {
110132
const { writer, broadcast: bc } = broadcast({ highWaterMark: 10 });
@@ -133,6 +155,7 @@ Promise.all([
133155
testDropNewest(),
134156
testBlockBackpressure(),
135157
testBlockBackpressureContent(),
158+
testStrictBackpressureOverflow(),
136159
testWritevAsync(),
137160
testEndSyncReturnValue(),
138161
]).then(common.mustCall());

0 commit comments

Comments
 (0)