1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

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.
This commit is contained in:
Matt Mastracci 2023-07-03 09:30:02 -06:00 committed by GitHub
parent 26c2abef7f
commit 2c2e6adae8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -427,7 +427,17 @@ async function asyncResponse(responseBodies, req, status, stream) {
responseRid = op_http_set_response_body_stream(req); responseRid = op_http_set_response_body_stream(req);
SetPrototypeAdd(responseBodies, responseRid); SetPrototypeAdd(responseBodies, responseRid);
op_http_set_promise_complete(req, status); 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); }, 250);
const { value: value2, done: done2 } = await reader.read(); const { value: value2, done: done2 } = await reader.read();