From 5457e741fae8272901d277836a396a52fada86da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Fri, 4 Jun 2021 01:32:36 +0200 Subject: fix: hang in op_http_next_request (#10836) This commit adds "CancelHandle" to "ConnResource" and changes "op_http_next_request" to await for the cancel signal. In turn when async iterating over "Deno.HttpConn" the iterator breaks upon closing of the resource. --- cli/tests/unit/http_test.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'cli/tests') diff --git a/cli/tests/unit/http_test.ts b/cli/tests/unit/http_test.ts index 9560394f0..df599c6f4 100644 --- a/cli/tests/unit/http_test.ts +++ b/cli/tests/unit/http_test.ts @@ -339,3 +339,37 @@ unitTest( await promise; }, ); + +unitTest( + { perms: { net: true } }, + async function httpServerNextRequestResolvesOnClose() { + const delay = (n: number) => + new Promise((resolve) => setTimeout(resolve, n)); + const httpConnList: Deno.HttpConn[] = []; + + async function serve(l: Deno.Listener) { + for await (const conn of l) { + (async () => { + const c = Deno.serveHttp(conn); + httpConnList.push(c); + for await (const { respondWith } of c) { + respondWith(new Response("hello")); + } + })(); + } + } + + const l = Deno.listen({ port: 4500 }); + serve(l); + + await delay(300); + const res = await fetch("http://localhost:4500/"); + const _text = await res.text(); + + // Close connection and listener. + httpConnList.forEach((conn) => conn.close()); + l.close(); + + await delay(300); + }, +); -- cgit v1.2.3