Closed antoniogamiz closed 4 years ago
Hey @antoniogamiz thanks for raising - not ideal at all given that really is the simplest usecase! 😅
Will try to spare some time soon to investigate - if you have time and are keen, please do have a dive into the code to figure out what async/promising thing is being left hanging.
It's odd this hasn't been picked up in the tests but haven't touched this in a month and may be that something in Oak / Deno has moved along since September... or just have been super lucky (or unlucky depending on how see it) with an async op race condition.
I know it's quite weird... At first, I thought it was due to some error in my files, but I have cleaned the cache and updated Deno to 1.4.6
and it's still happening.
I have downloaded this repo and I have run the tests but they are ok so...
I will try to investigate what's being left hanging.
Haven't dug too deeply, but from a quick reminder of the code, performing:
const request = await superdeno(app);
Will launch an Oak server and resolve with a promise which we are awaiting. Given nothing then stops said Oak sever, my guesses are that it (the server) is effectively the async op that is not cleaned up (or more accurately the async iterator inside the Oak server that processes requests hasn't been escaped).
Hence I'm curious if the issue goes away if you actually complete the usage of superdeno
as documented and make an action / assertion - superdeno has it's own internal logic to close the Oak server using an AbortController
, and this will only be fired when the underlying superdeno .end()
method is called, either implicitly or explicitly (REF: https://github.com/asos-craigmorten/superdeno/blob/main/src/test.ts#L350)
For instance, updating to the following solves it for me:
import { Application} from "https://deno.land/x/oak@v6.3.1/mod.ts";
import { superoak } from "https://deno.land/x/superoak@2.3.1/mod.ts";
const app = new Application();
app.use((ctx: any) => {
ctx.response.body = "Hello world!";
});
Deno.test("Example", async () => {
const request = await superoak(app);
await request.get("/"); // Need to invoke at least one superdeno method otherwise the underlying server is left runner forever (well... until it gets cleaned up by Deno which will tell you off).
});
And why does this fail, then? It produces the same error:
import { Application } from "https://deno.land/x/oak@v6.3.1/mod.ts";
import { superoak } from "https://deno.land/x/superoak@2.3.1/mod.ts";
const app = new Application();
app.use((ctx: any) => {
ctx.response.body = "Hello world!";
});
Deno.test("Example", async () => {
const request = await superoak(app);
await request.get("/").expect({});
});
I'm passing an object because my endpoint returns a JSON, so I want to test that.
Sorry ignore those two replies, what you have said works great. Thanks!
Issue
Setup:
I am trying to run a simple test in my app, but it constantly fails because of leaking async ops, even though there's nothing running.
Details
To run:
deno test --allow-net <that code>.ts
Error log: