Skip to content

Commit e383a1d

Browse files
authored
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> PR-URL: #64420 Fixes: #64419 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
1 parent 68dc116 commit e383a1d

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
@@ -591,7 +591,7 @@ class BroadcastWriter {
591591

592592
if (policy === 'strict') {
593593
if (this.#pendingWrites.length >= 1) {
594-
throw new ERR_INVALID_STATE.TypeError(
594+
throw new ERR_INVALID_STATE.RangeError(
595595
'Backpressure violation: too many pending writes. ' +
596596
'Await each write() call to respect backpressure.');
597597
}

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

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

116+
async function testStrictBackpressureOverflow() {
117+
const { writer } = broadcast({
118+
budget: 16384,
119+
backpressure: 'strict',
120+
});
121+
122+
await writer.write(new Uint8Array(16384));
123+
const pending = writer.write('b');
124+
125+
await assert.rejects(writer.write('c'), {
126+
name: 'RangeError',
127+
code: 'ERR_INVALID_STATE',
128+
});
129+
130+
writer.fail();
131+
await assert.rejects(pending, {
132+
name: 'TypeError',
133+
code: 'ERR_INVALID_STATE',
134+
message: 'Invalid state: Failed',
135+
});
136+
}
137+
116138
// Writev async path
117139
async function testWritevAsync() {
118140
const { writer, broadcast: bc } = broadcast({ budget: 16384 });
@@ -141,6 +163,7 @@ Promise.all([
141163
testDropNewest(),
142164
testBlockBackpressure(),
143165
testBlockBackpressureContent(),
166+
testStrictBackpressureOverflow(),
144167
testWritevAsync(),
145168
testEndSyncReturnValue(),
146169
]).then(common.mustCall());

0 commit comments

Comments
 (0)