Skip to content

Commit f2ada96

Browse files
committed
stream: prevent unhandled rejection in Broadcast.from() pump
`Broadcast.from()` used a fire-and-forget async IIFE to pump data from source to writer. While the catch block routes all errors to `writer.fail()` which never rejects, the IIFE's promise was unguarded against future invariant changes. Extract the IIFE to a named pump function and attach a no-op rejection handler via `PromisePrototypeThen`.
1 parent 9b21cbd commit f2ada96

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

lib/internal/streams/iter/broadcast.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const {
1313
ArrayPrototypeSlice,
1414
MathMax,
1515
Promise,
16+
PromisePrototypeThen,
1617
PromiseResolve,
1718
SafeSet,
1819
String,
@@ -679,7 +680,7 @@ const Broadcast = {
679680
const result = broadcast(options);
680681
const signal = options?.signal;
681682

682-
(async () => {
683+
const pump = async () => {
683684
const w = result.writer;
684685
try {
685686
if (isAsyncIterable(input)) {
@@ -721,7 +722,8 @@ const Broadcast = {
721722
await w.fail(err);
722723
}
723724
}
724-
})();
725+
};
726+
PromisePrototypeThen(pump(), undefined, () => {});
725727

726728
return result;
727729
},

0 commit comments

Comments
 (0)