summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2021-09-08 10:12:23 +0200
committerGitHub <noreply@github.com>2021-09-08 10:12:23 +0200
commit2de5587547247e3acdffecae1c74caf52a021580 (patch)
tree65405417c62008ffcf73a6721bc032b69775279e /cli/tests
parentc04117134ecb07fb6379bfe1057c9da8e0c4f206 (diff)
fix(ext/http): resource leak if request body is not consumed (#11955)
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/unit/http_test.ts42
1 files changed, 42 insertions, 0 deletions
diff --git a/cli/tests/unit/http_test.ts b/cli/tests/unit/http_test.ts
index ccacfd751..c243d6442 100644
--- a/cli/tests/unit/http_test.ts
+++ b/cli/tests/unit/http_test.ts
@@ -882,3 +882,45 @@ unitTest(
clientConn.close();
},
);
+
+// https://github.com/denoland/deno/issues/11926
+unitTest(
+ { perms: { net: true } },
+ async function httpServerDoesntLeakResources2() {
+ let listener: Deno.Listener;
+ let httpConn: Deno.HttpConn;
+
+ const promise = (async () => {
+ listener = Deno.listen({ port: 4502 });
+ for await (const conn of listener) {
+ httpConn = Deno.serveHttp(conn);
+ for await (const { request, respondWith } of httpConn) {
+ assertEquals(new URL(request.url).href, "http://127.0.0.1:4502/");
+ // not reading request body on purpose
+ respondWith(new Response("ok"));
+ }
+ }
+ })();
+
+ const resourcesBefore = Deno.resources();
+ const response = await fetch("http://127.0.0.1:4502", {
+ method: "POST",
+ body: "hello world",
+ });
+ await response.text();
+ const resourcesAfter = Deno.resources();
+ // verify that the only new resource is "httpConnection", to make
+ // sure "request" resource is closed even if its body was not read
+ // by server handler
+
+ for (const rid of Object.keys(resourcesBefore)) {
+ delete resourcesAfter[Number(rid)];
+ }
+
+ assertEquals(Object.keys(resourcesAfter).length, 1);
+
+ listener!.close();
+ httpConn!.close();
+ await promise;
+ },
+);