summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Mastracci <matthew@mastracci.com>2023-07-03 09:30:02 -0600
committerGitHub <noreply@github.com>2023-07-03 15:30:02 +0000
commit2c2e6adae86874ccb9a3fd2843cf2b50a0847bac (patch)
treec6df643bf1c5584cdaa4787fda0c517c8522f0de
parent26c2abef7fce9aaad18cd86416dd9b032c9fa767 (diff)
fix(ext/http): Catch errors in eager stream timeout to avoid uncaught promise rejections (#19691)
Fixes #19687 by adding a rejection handler to the write inside the setTimeout. There is a small window where the promise is actually not awaited and may reject without a handler.
-rw-r--r--ext/http/00_serve.js12
1 files changed, 11 insertions, 1 deletions
diff --git a/ext/http/00_serve.js b/ext/http/00_serve.js
index 761c3219e..43b04ff28 100644
--- a/ext/http/00_serve.js
+++ b/ext/http/00_serve.js
@@ -427,7 +427,17 @@ async function asyncResponse(responseBodies, req, status, stream) {
responseRid = op_http_set_response_body_stream(req);
SetPrototypeAdd(responseBodies, responseRid);
op_http_set_promise_complete(req, status);
- timeoutPromise = core.writeAll(responseRid, value1);
+ // TODO(mmastrac): if this promise fails before we get to the await below, it crashes
+ // the process with an error:
+ //
+ // 'Uncaught (in promise) BadResource: failed to write'.
+ //
+ // To avoid this, we're going to swallow errors here and allow the code later in the
+ // file to re-throw them in a way that doesn't appear to be an uncaught promise rejection.
+ timeoutPromise = PromisePrototypeCatch(
+ core.writeAll(responseRid, value1),
+ () => null,
+ );
}, 250);
const { value: value2, done: done2 } = await reader.read();