socket.io-client icon indicating copy to clipboard operation
socket.io-client copied to clipboard

Cannot catch websocket error

Open ASBaj opened this issue 6 years ago • 5 comments

You want to:

  • [x] report a bug
  • [ ] request a feature

Current behaviour

What is actually happening? When an unhanded websocket error is thrown (transport.js 64), there does not appear to be a way to prevent the node.js application from crashing.

Steps to reproduce (if the current behaviour is a bug)

  1. Connect your socket.io client to a socket.io server
  2. Connect a device to your network that has the same IP address as your socket.io server
  3. Disconnect your socket.io server from the network
  4. The socket.io client will crash with this error.

Expected behaviour

The socket.io client would disconnect, and then go into a reconnecting state.

Setup

  • OS: Windows Server 2012 R2
  • browser: Node.js
  • socket.io version: 2.1.1

ASBaj avatar Oct 04 '18 20:10 ASBaj

Turns out the error can be caught, with this:

process.on('uncaughtException', function (err) { console.log('UNCAUGHT EXCEPTION - keeping process alive:', err); // err.message is "foobar" });

Found it somewhere on StackExchange. Does the job, but I still think it would be better if we had a way to catch this without having to do a generic catch-all.

ASBaj avatar Oct 04 '18 21:10 ASBaj

@ASBaj why did you reopen?

4F2E4A2E avatar Oct 09 '18 14:10 4F2E4A2E

Because the process.on event I linked earlier catches all uncaught exceptions, irrespective of their source. According to a variety of opinions I read, this is not considered to be best practice; if an unhandled exception occurs, the program should crash, and the individual exception should be dealt with, and hence, we should have a way to catch this specific exception.

ASBaj avatar Oct 09 '18 16:10 ASBaj

I have the same issue, is there any solution for this problem. I need to catch the error and know which socket cause the problem (the source) because I have multiple client socket to different servers.

karmac2015 avatar Oct 31 '18 08:10 karmac2015

Any update on this issue after 2 years?

Maximvdw avatar Apr 03 '20 19:04 Maximvdw