-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Deno.Listener#close()
doesn't release the address after accept()
called
#25480
Comments
I tried this patch to force close the tcp socket fd kt3k@31cdde6 But it ended up with the error |
A workaround for the issue #25480 `Deno.Listener` can't be closed synchronously after `accept()` is called. This PR delays the `accept` call 2 ticks (The listener callback is called 1 tick later. So the 1 tick delay is not enough), and makes `net.Server` capable of being closed synchronously. This unblocks `npm:detect-port` and `npm:portfinder` closes #18301 closes #25175
@kt3k Does it work if you move the close() {
core.close(this.#rid);
if (this.addr.transport === "tcp") {
op_net_cancel_listener_tcp(this.#rid);
}
} |
Here's an strace for Deno vs Node. https://gist.github.com/littledivy/21d35550829f7dae078c023075af3c70
const server = net.createServer(() => {}); // <-- accept().try_or_cancel(&cancel_handle)?.await
server.once("listening", () => {
server.close(); // <-- cancel_handle.cancel()
server.listen(8081, host2); // <-- err, cancellation is not complete
setTimeout(() => server.listen(8081, host2)) // <-- works, cancellation complete on next tick
});
|
This caused
Thanks for the analysis! This is good to know.
This works for
Divy, thanks for the analysis! I'm closing this for now as there seems no better way than that workaround. |
Deno.Listener#close()
can release the listening address synchronously ifaccept()
is not called yet. The below example runs without errors:However if
accept()
is called onlistener
, it can't release the address synchronously atclose()
call. The below example throwsAddrInUse
error:This behavior blocks port-scanning npm packages (e.g.
npm:portfinder
,npm:detect-port
). ref #25175 #18301The text was updated successfully, but these errors were encountered: