Reputation: 3640
I am pretty sure that the only place in my code that could be throwing this error, based on the port number, would be the following code.
try {
webServer = new WebSocketServer({
port: args.listen
});
} catch (exception) {
if (exception instanceof Error) {
logger.log('Could not bind port ' + args.listen + ' for ' + args.name +', already in use.');
}
}
I tried removing the if
statement, but it did not change the result. When this runs if the port if already bound by a process I get the following error which I would like to catch and report without causing the process to exit.
events.js:160 throw er; // Unhandled 'error' event ^
Error: listen EADDRINUSE :::6010
at Object.exports._errnoException (util.js:1020:11)
at exports._exceptionWithHostPort (util.js:1043:20)
at Server._listen2 (net.js:1262:14)
at listen (net.js:1298:10)
at net.js:1408:9
at _combinedTickCallback (internal/process/next_tick.js:83:11)
at process._tickCallback (internal/process/next_tick.js:104:9)
at Module.runMain (module.js:606:11)
at run (bootstrap_node.js:383:7)
at startup (bootstrap_node.js:149:9)
Why would this not be caught by the try...catch
?
Upvotes: 0
Views: 281
Reputation: 1609
I think you need to try this. I think that is how we deal with websocket errors.
websocket.onerror = function(evt) {
onError(evt)
};
Upvotes: 1