diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2021-06-04 01:32:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-04 01:32:36 +0200 |
commit | 5457e741fae8272901d277836a396a52fada86da (patch) | |
tree | 082f647692a13b1f0771e62cb1d9989bc2cafc8c /cli/tests | |
parent | 41e9a21307f87e0a79766fc879a3a0b06dc57eb2 (diff) |
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.
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/unit/http_test.ts | 34 |
1 files changed, 34 insertions, 0 deletions
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); + }, +); |