New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Server hangs on close #3593
Comments
Seems like a TcpStream is not getting closed. If you do: test(async function foo() {
createServer();
const res = await fetch("http://127.0.0.1:8080/hello");
assertEquals(await res.text(), "/hello");
s.close();
console.table(Deno.resources());
}); you can see below in 0.27.0:
but in 0.28.0:
|
Isolate seems to have one pending op at the end and doesn't get woken up. |
This |
More investigation shows that it is a |
Possibly related: #3160. |
This might have been a Actually, maybe related to seanmonstar/reqwest#746 |
We can try with tokio upgrade to 0.2.8 as mentioned in seanmonstar/reqwest#746 (comment) |
FYI: I tested described problem with It needs further investigation |
Update: did some investigation, the problem is in this bit: for await (const req of s) {
req.respond({ body: encoder.encode(req.url) });
} Async iterator is never notified that server is closing and thus never closes the tcp connection, hence "tcpStream" visible in resource table. @kevinkassimo could you take a look at it? |
My repro: import { serve } from "./std/http/server.ts";
const server = serve(":8080");
// Iterate requests asynchronously.
(async () => {
for await (const request of server) {
console.log("Request received.");
await request.respond({ body: new TextEncoder().encode("Hi!") });
console.log("Responded.");
}
console.log(`Done iterating requests!`);
})();
// Send a request.
console.log("Sending request.");
const res = await fetch("http://127.0.0.1:8080/hello");
await res.text(); // Consuming the body so the resource closes.
console.log("Response received!");
// Close the server.
server.close();
console.log("Server closed!")
setTimeout(() => console.log(Deno.resources()), 500); If a connection closes while the server is reading it, the read hangs. I get this deno v0.29.0 and std on master:
and it hangs there. I applied this patch (nayeemrmn@ce8ebf6) to short-circuit the read on server close -- and got this:
Great, correct output... except it still hangs for some reason! 🤷♂️ |
@bartlomieju I'll look deeper into this tomorrow @nayeemrmn The latter is the exact problem I was describing in #3593 (comment) |
Cool, I think #3656 and #3657 are related - there's a good chance that process is hanging because of shared HTTP client, but I have not experienced it (MacOS). What OS are you testing on? EDIT: EDIT2: Yeah, so pending op is EDIT3: Just call Deno.shutdown(conn.rid, 0);
Deno.shutdown(conn.rid, 1);
conn.close(); |
Ah! I knew it was because the read wasn't actually aborted, I didn't know |
Fixed in #3657 |
following code works at v0.27 but hangs at v0.28
The text was updated successfully, but these errors were encountered: