Currently when an error occurs in a NodeJS server (eg: Buffer "out of bounds"), the entire server grinds to a halt. Is there a way to configure it such that only the socket on which the error occured gets disconnected leaving the server online and the other connections active? I could use the "uncaughtException" error but then there would be no way of knowing which socket caused the error/crashed. How is this handled typically?
Asked
Active
Viewed 273 times
1 Answers
0
You can use the try .. catch(err)
construct to catch any exceptions occurring within any callback of the the socket, and subsequently socket.end()
, to disconnect the client if an error occurs. This prevents the entire server from crashing. Obviously for the other "uncaught" errors you'll have to resort to the "uncaughtException" callback, which does not end the server. Why don't you read this and this for more answers.

Community
- 1
- 1

Robin Rodricks
- 110,798
- 141
- 398
- 607