diff options
author | Matt Mastracci <matthew@mastracci.com> | 2023-05-16 17:00:59 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-16 17:00:59 -0600 |
commit | a22388bbd1377f75d3b873c59f6836cd12c2abe5 (patch) | |
tree | 04b9879ab7172884b3417fdf1a3d170564c54726 /cli/tests | |
parent | 9ba2c4c42fcbadea1f19c67c88b5cbc4c97804f3 (diff) |
fix(ext/http): Ensure cancelled requests don't crash Deno.serve (#19154)
Fixes for various `Attemped to access invalid request` bugs (#19058,
#15427, #17213).
We did not wait for both a drop event and a completion event before
removing items from the slab table. This ensures that we do so.
In addition, the slab methods are refactored out into `slab.rs` for
maintainability.
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/unit/serve_test.ts | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/cli/tests/unit/serve_test.ts b/cli/tests/unit/serve_test.ts index 2bd2314b7..15dc84a28 100644 --- a/cli/tests/unit/serve_test.ts +++ b/cli/tests/unit/serve_test.ts @@ -15,7 +15,6 @@ import { deferred, fail, } from "./test_util.ts"; -import { consoleSize } from "../../../runtime/js/40_tty.js"; const { upgradeHttpRaw, @@ -665,6 +664,38 @@ Deno.test({ permissions: { net: true } }, async function httpServerClose() { await server; }); +// https://github.com/denoland/deno/issues/15427 +Deno.test({ permissions: { net: true } }, async function httpServerCloseGet() { + const ac = new AbortController(); + const listeningPromise = deferred(); + const requestPromise = deferred(); + const responsePromise = deferred(); + const server = Deno.serve({ + handler: async () => { + requestPromise.resolve(); + await new Promise((r) => setTimeout(r, 500)); + responsePromise.resolve(); + return new Response("ok"); + }, + port: 4501, + signal: ac.signal, + onListen: onListen(listeningPromise), + onError: createOnErrorCb(ac), + }); + await listeningPromise; + const conn = await Deno.connect({ port: 4501 }); + const encoder = new TextEncoder(); + const body = + `GET / HTTP/1.1\r\nHost: example.domain\r\nConnection: close\r\n\r\n`; + const writeResult = await conn.write(encoder.encode(body)); + assertEquals(body.length, writeResult); + await requestPromise; + conn.close(); + await responsePromise; + ac.abort(); + await server; +}); + // FIXME: Deno.test( { permissions: { net: true } }, |