KyleJuneK
Denoβ€’3y agoβ€’
9 replies
KyleJune

Leaking resources from inbound HTTP connections in tests

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()`.

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, "");
});
Was this page helpful?