D
Deno

help

Leaking resources from inbound HTTP connections in tests

Kkylejune11/18/2023
Anyone have any ideas why I would be getting the following error. I'm using an oak server that is started before all the tests and closed after they all finish.
error: Leaking resources:
- An inbound HTTP connection (rid 7) was accepted before the test started, but was closed during the test. Do not close resources in a test that were not created during that test.
- An inbound HTTP connection (rid 21) was accepted during the test, but not closed during the test. Close the inbound HTTP connection by calling `httpConn.close()`.
error: Leaking resources:
- An inbound HTTP connection (rid 7) was accepted before the test started, but was closed during the test. Do not close resources in a test that were not created during that test.
- An inbound HTTP connection (rid 21) was accepted during the test, but not closed during the test. Close the inbound HTTP connection by calling `httpConn.close()`.
It happens in all test cases after the first. I await the response, so I'm not sure why the connection is still considered open when the test ends. All the assertions pass, the only thing that causes failure is the leaking resource. In oak I don't see an option to close the response.
it(notFoundTests, "without extension", async () => {
const response = await fetch("http://localhost:9001/api/invalid");
const body = await response.json();
assertEquals(response.status, 404);
assertEquals(
response.headers.get("Content-Type"),
"application/json; charset=UTF-8",
);
assert(response.headers.has("X-Response-Time"));
assert(!response.headers.has("etag"));
assertEquals(body, {
error: { name: "NotFoundError", message: "Not found", status: 404 },
});
});

it(notFoundTests, "with json extension", async () => {
const response = await fetch("http://localhost:9001/api/invalid.json");
const body = await response.text();
assertEquals(response.status, 404);
assertEquals(response.headers.get("Content-Type"), null);
assert(response.headers.has("X-Response-Time"));
assert(!response.headers.has("etag"));
assertEquals(body, "");
});
it(notFoundTests, "without extension", async () => {
const response = await fetch("http://localhost:9001/api/invalid");
const body = await response.json();
assertEquals(response.status, 404);
assertEquals(
response.headers.get("Content-Type"),
"application/json; charset=UTF-8",
);
assert(response.headers.has("X-Response-Time"));
assert(!response.headers.has("etag"));
assertEquals(body, {
error: { name: "NotFoundError", message: "Not found", status: 404 },
});
});

it(notFoundTests, "with json extension", async () => {
const response = await fetch("http://localhost:9001/api/invalid.json");
const body = await response.text();
assertEquals(response.status, 404);
assertEquals(response.headers.get("Content-Type"), null);
assert(response.headers.has("X-Response-Time"));
assert(!response.headers.has("etag"));
assertEquals(body, "");
});
I tried adding await delay(1000) to the end of each test, even with that delay, the problem still happens. I don't have an issue with Deno v1.36.4, I'm going to try seeing if I can find the version this issue starts in. Looks like the last working version is v1.37.0, then it breaks in v1.37.1 and beyond. Same version of oak and all other dependencies. So the issue appears to be in Deno.
DAHDeno AI Helper11/18/2023
Based on the documentation, the error message you're seeing is related to resource sanitization in Deno's test runner. This feature checks that all resources created during a test are also closed during the same test. In your case, it seems that HTTP connections are being left open after the tests finish. The error message suggests two issues: 1. An inbound HTTP connection (rid 7) was accepted before the test started, but was closed during the test. This suggests that a connection was established before the test began and was closed within the test. The test runner expects that resources created outside of a test are not closed within the test. 2. An inbound HTTP connection (rid 21) was accepted during the test, but not closed during the test. This suggests that a connection was established during the test but was not closed before the test ended. The fetch function you're using to make HTTP requests in your tests does not automatically close the connection. Even though you're awaiting the response, the underlying connection is still open. In the Oak framework, the connection is typically closed automatically after the response is sent. However, in your tests, you're not directly interacting with the Oak application, but rather sending HTTP requests to the server. This means that the connection's lifecycle isn't managed by your test code, but by the server and the client (the fetch function). Unfortunately, the Deno documentation does not provide a clear solution for this issue. You might need to look for a way to ensure that the HTTP connections are closed after each test. This could involve some changes to how you're structuring your tests or how you're managing your Oak server.
DAHDeno AI Helper11/18/2023
馃 Oops! Can you pinpoint where I went wrong to help me improve? 馃搱
Kkylejune11/18/2023
I think it's this PR that caused the issue. It seems to be the only one related to HTTP and it says it's for ensuring that resources are closed. https://github.com/denoland/deno/pull/20641
Kkylejune11/18/2023
I just tried that one by doing the following and it seems like that isn't what caused the issue. hmm. deno upgrade --canary --version a27ee8f368dbac33141fdcb9a17d0e4ea907b8ef
Kkylejune11/18/2023
This is the last working version.
deno 1.37.0+6f87962 (canary, x86_64-unknown-linux-gnu)
v8 11.8.172.6
typescript 5.2.2
deno 1.37.0+6f87962 (canary, x86_64-unknown-linux-gnu)
v8 11.8.172.6
typescript 5.2.2
The issue starts in the next canary build.
deno 1.37.0+c68650d (canary, x86_64-unknown-linux-gnu)
v8 11.8.172.6
typescript 5.2.2
deno 1.37.0+c68650d (canary, x86_64-unknown-linux-gnu)
v8 11.8.172.6
typescript 5.2.2
This is the PR that causes the issue. https://github.com/denoland/deno/pull/20680
GitHub
fix(cli/test): clear connection pool after tests by lucacasonato 路 ...
This helps reduce flakes where a test starts an HTTP server and makes a request using fetch, then shuts down the server, then starting a new test with a new server, but the connection pool still ha...
Kkylejune11/18/2023
I created an issue for the problem on github. https://github.com/denoland/deno/issues/21256
GitHub
Race condition in Deno.serve() and fetch() 路 Issue #21256 路 denolan...
The following code sample is from one of my private repositories. The beforeAll starts an oak server and the afterAll closes it. So all test cases are making API calls to the same oak server. These...

Looking for more? Join the community!

Recommended Posts
Preact Hello World is not working/** @jsxImportSource https://esm.sh/preact */ import { useState } from "https://esm.sh/preact/hooks"using imports map to map no-suffix imports to suffix importsI was hoping i might be able to use an import map in my deno.json like this: ``` "imports": { "./sdocker-jupyter with deno?Anyone know any good pre-made solutions? Thanks!Importing JSON files with a different file extension fails as "Unknown module"When trying to import a json file with import attributes that doesn't end with .json Deno gives the BroadcastChannel vs EventSource vs WebSocketWhy would one uses BroadcastChannel, over EventSource, or WebSocket? Could anyone provide clear exaReally Excited About Dino JupyterI tried to install the Kernel on Windows SANS - WSL. Here is the output: deno jupyter --unstable Trying to benchmark `Deno.remove` but it fails``` deno bench --allow-write bench.ts Check file:///C:/Users/babak/OneDrive/Desktop/deno-benchmark-3Plot Vega-Lite in Jupyter Notebook running the Deno kernelHello, I am very new to Deno... I wanted to see if I can produce some interactive Vega visualizaitonSegfault when creating second rust MainWorker in programHello. Not sure if this is the place to ask since it seems to be a v8 issue (or perhaps an issue wiHow can I use "Logging with colors" with `"npm:log-update"`Hi https://examples.deno.land/color-logging I don't want to use Chalk because it's not properly typeHow to uploading images from frontend to Deno.serve()Hey, can someone please give me a vanilla code example on how to upload files from my frontend applDeno Deploy JSON importI'm using zod-i18n-map library for error translation, which requires an import for the library itselMost efficient way to broadcast messages globally across main script and workers?I basically want a simple message bus that is global to all my workers + the main script, without reWhat is the process for deploying a jupyter notebook made using deno?I have webdev experience and was using Observable. I was looking for alternatives that use javascripPostGraphile on DenoDoes PostGraphile work with Deno? Trying to see if I can run PostGraphile as a serverless function oIs there any way to disable Deno's Intellisense feature without disabling Deno itself?When programming with Deno, I've noticed how relatively slow the lang server is, and I need intellisDeploying Lume to github pagesI'm totaly new to this, but have been following instructions to build a site with lume. It works locBest hardware for Deno development?I am looking for a new laptop / desktop for Deno development as my current setup seems no longer viaHow do I make the crypto.subtle.digest algo flexible?This is a learning moment, bear with me. 馃槄 I can hard code an algo for the digest like this: ```twhat鈥檚 the current best practice for bundling?Is it deno esbuild? Wondering what supports npm specifiers and bundling atm