From 1d7203c24c2ca2fa5c75a149324ebd5bf806102a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Og=C3=B3rek?= Date: Sat, 14 Jan 2023 15:06:28 +0100 Subject: fix(ext/flash): Correctly handle errors for chunked responses (#17303) The leading cause of the problem was that `handleResponse` has `tryRespondChunked` passed as an argument, which in turn is implemented as a call to `core.ops.op_try_flash_respond_chuncked`, that throws in the repro code. `handleResponse` was not handled correctly, as it not returned any value, and had no `catch` attached to it. It also effectively was never correctly handled inside two other blocks with `resp.then` and `PromisePrototypeCatch(PromisePrototypeThen(resp, "..."))` as well, as it just short-circuited the promise with an empty resolve, instead of relying on the last `(async () => {})` block. This change makes `handleResponse` return a correct value and attach `onError` handler to the "non-thenable" variant of response handling code. --- ext/flash/01_http.js | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'ext') diff --git a/ext/flash/01_http.js b/ext/flash/01_http.js index e76914e72..e76f4de52 100644 --- a/ext/flash/01_http.js +++ b/ext/flash/01_http.js @@ -327,7 +327,7 @@ ); } - (async () => { + return (async () => { if (!ws) { if (hasBody && body[_state] !== "closed") { // TODO(@littledivy): Optimize by draining in a single op. @@ -590,7 +590,6 @@ ), onError, ); - continue; } else if (typeof resp?.then === "function") { resp.then((resp) => handleResponse( @@ -606,24 +605,23 @@ tryRespondChunked, ) ).catch(onError); - continue; + } else { + handleResponse( + req, + resp, + body, + hasBody, + method, + serverId, + i, + respondFast, + respondChunked, + tryRespondChunked, + ).catch(onError); } } catch (e) { resp = await onError(e); } - - handleResponse( - req, - resp, - body, - hasBody, - method, - serverId, - i, - respondFast, - respondChunked, - tryRespondChunked, - ); } offset += tokens; -- cgit v1.2.3