Skip to content
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

node:http server throws uncatchable AddrInUse exception #20186

Closed
jamesdiacono opened this issue Aug 17, 2023 · 1 comment · Fixed by #20200
Closed

node:http server throws uncatchable AddrInUse exception #20186

jamesdiacono opened this issue Aug 17, 2023 · 1 comment · Fixed by #20200
Assignees
Labels
bug Something isn't working correctly node compat

Comments

@jamesdiacono
Copy link
Contributor

It appears that the polyfill for Node.js's server does not correctly emit an "error" event when asked to listen on a port that is not available. To reproduce the problem, try running the following script in two separate Deno instances.

import http from "node:http";
const server = http.createServer();
server.once("error", function (error) {
    console.log("Failed to listen", error);
});
server.listen(9000, () => console.log("listening"));

The first instance logs "listening", which is correct. But the second instance crashes, instead of logging "Failed to listen" to stderr.

Reproduced in Deno v1.36.1 on MacOS.

I believe the problem is that there is no try...catch around the call to Deno.listen, which throws if the port is not available:

nextTick(() => this._serve());

this.#server = serve(

listener = listen(listenOpts);

@jamesdiacono
Copy link
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly node compat
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants