-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Cannot catch EADDRINUSE from server.start() #2561
Comments
We don't wrap everything in try..catch code. Only place throws are handled is in userland code called as part of request processing so that we can return a 500 page. |
Well, if you don't handle errors well, then I doubt whether it's safe to use hapi in production. EADDRINUSE is an error to be expected in the listen function and handling it is as simple as adding the callback to the |
Can't you just check the exit status ( |
@jzorn I use But still, letting the application crash is a bug to me. You don't know anything about the application's open database transactions, half-written files and other ongoing operations. Hapi is just a library and it should not crash the process without an important reason. And if in your opinion it's still ok, then the documentation should tell Hapi users something like:
|
I am not sure I follow the reasoning behind the need to handle the EADDRINUSE at startup. It apears only at startup, right? At least I only saw it there. If this is the case, then you basically don’t have any database connections which are in use yet, because nobody could connect to the app due it failing to start. |
Can't you use forever's |
@mik01aj If you rely on In general, we cannot possibly handle every exception every function might throw. Node has made a choice to throw in async methods when the basic inputs are wrong, even when a callback is provided. I am happy to take a pull request that states simply that the method may throw and give this as an example. |
This is wrong. The callback is never called on errors. The only way to catch the error, is to add an @hueniverse I agree on your point regarding relying on This is not a matter of adding try..catch but rather of respecting the api of the Note that this issue will also trigger on this (with another error): var server = new Hapi.Server();
server.connection({ host: 'does.not.resolve' });
server.start(function (err) {}); |
@kanongil fair enough. I'll take a PR. |
When I try to call
server.start(callback)
, and the port is in use, the script crashes with a message:I would expect the
callback
to be called instead (with the error, of course).The text was updated successfully, but these errors were encountered: