Skip to content

Commit babb19d

Browse files
committed
quic: address qard review feedback
1 parent 350bda3 commit babb19d

3 files changed

Lines changed: 10 additions & 15 deletions

File tree

doc/api/quic.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1497,7 +1497,7 @@ The following body source types are supported:
14971497
* `AsyncIterable`, `Iterable` — Each yielded chunk (string or
14981498
`Uint8Array`) is written incrementally in streaming mode.
14991499
* `Promise` — Awaited; the resolved value is used as the body (subject
1500-
to the same type rules, with a nesting depth limit).
1500+
to the same type rules).
15011501

15021502
Throws `ERR_INVALID_STATE` if the outbound is already configured or if
15031503
the writer has been accessed.

lib/internal/quic/quic.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -910,28 +910,23 @@ function applyCallbacks(session, cbs) {
910910
* @param {QuicStream} stream The JS stream object
911911
* @param {*} body The body source
912912
*/
913-
const kMaxConfigureOutboundDepth = 3;
914913
const kDefaultHighWaterMark = 65536;
915914
const kDefaultMaxPendingDatagrams = 128;
916915

917-
function configureOutbound(handle, stream, body, depth = 0) {
918-
if (depth > kMaxConfigureOutboundDepth) {
919-
throw new ERR_INVALID_STATE(
920-
'Body source resolved to too many nested promises');
921-
}
922-
916+
function configureOutbound(handle, stream, body) {
923917
// body: null - close writable side immediately (FIN)
924918
if (body === null) {
925919
handle.initStreamingSource();
926920
handle.endWrite();
927921
return;
928922
}
929923

930-
// Handle Promise - await and recurse with depth limit
924+
// Handle Promise - await and recurse. Native promises auto-flatten,
925+
// so the resolved value will never itself be a promise.
931926
if (isPromise(body)) {
932927
PromisePrototypeThen(
933928
body,
934-
(resolved) => configureOutbound(handle, stream, resolved, depth + 1),
929+
(resolved) => configureOutbound(handle, stream, resolved),
935930
(err) => {
936931
if (!stream.destroyed) {
937932
stream.destroy(err);

test/parallel/test-quic-stream-body-promise-reject.mjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Flags: --experimental-quic --experimental-stream-iter --no-warnings
22

3-
// Test: body: Promise rejection and nested promise depth.
4-
// Promise rejection during body configuration errors the stream.
5-
// Nested promises are resolved up to the depth limit.
3+
// Test: body: nested promise resolution.
4+
// Native promises auto-flatten, so Promise<Promise<string>> resolves
5+
// to the inner string value.
66

77
import { hasQuic, skip, mustCall } from '../common/index.mjs';
88
import assert from 'node:assert';
@@ -16,8 +16,8 @@ if (!hasQuic) {
1616
const { listen, connect } = await import('../common/quic.mjs');
1717
const { bytes } = await import('stream/iter');
1818

19-
// Nested promises — the body is resolved recursively up to
20-
// depth 3. A Promise<Promise<string>> should work.
19+
// Nested promises — native promises auto-flatten, so the
20+
// resolved value is never itself a promise.
2121
{
2222
const serverDone = Promise.withResolvers();
2323

0 commit comments

Comments
 (0)