summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/tests/unit/http_test.ts46
-rw-r--r--ext/http/lib.rs9
2 files changed, 54 insertions, 1 deletions
diff --git a/cli/tests/unit/http_test.ts b/cli/tests/unit/http_test.ts
index f93d28efa..2dc08cfa1 100644
--- a/cli/tests/unit/http_test.ts
+++ b/cli/tests/unit/http_test.ts
@@ -936,3 +936,49 @@ unitTest(
await promise;
},
);
+
+// https://github.com/denoland/deno/pull/12216
+unitTest(
+ { permissions: { net: true } },
+ async function droppedConnSenderNoPanic() {
+ async function server(listener: Deno.Listener) {
+ const conn = await listener.accept();
+ const http = Deno.serveHttp(conn);
+
+ for (;;) {
+ const req = await http.nextRequest();
+ if (req == null) break;
+
+ nextloop()
+ .then(() => {
+ http.close();
+ return req.respondWith(new Response("boom"));
+ })
+ .catch(() => {});
+ }
+
+ try {
+ http.close();
+ } catch {
+ "nop";
+ }
+
+ listener.close();
+ }
+
+ async function client() {
+ const resp = await fetch("http://127.0.0.1:8000/");
+ await resp.body?.cancel();
+ }
+
+ function nextloop() {
+ return new Promise((resolve) => setTimeout(resolve, 0));
+ }
+
+ async function main() {
+ const listener = Deno.listen({ port: 8000 });
+ await Promise.all([server(listener), client()]);
+ }
+ await main();
+ },
+);
diff --git a/ext/http/lib.rs b/ext/http/lib.rs
index 9aef3d370..aabf5d839 100644
--- a/ext/http/lib.rs
+++ b/ext/http/lib.rs
@@ -108,7 +108,14 @@ impl HyperService<Request<Body>> for Service {
response_tx: resp_tx,
});
- async move { Ok(resp_rx.await.unwrap()) }.boxed_local()
+ async move {
+ resp_rx.await.or_else(|_|
+ // Fallback dummy response in case sender was dropped due to closed conn
+ Response::builder()
+ .status(hyper::StatusCode::INTERNAL_SERVER_ERROR)
+ .body(vec![].into()))
+ }
+ .boxed_local()
}
}