Open jonathan-roy opened 5 years ago
@jonathan-roy, the steam error event is the right way to detect stream errors associated any normal stream communication errors in node. however, when we wrote this module, we never thought to emit connection or other errs from the clib layer correctly (in the idiomatic node way that you're referencing).
I'm open to review a PR request if you would like to take stab at fixing this. You would need to make sure to call Socket's emit('error', withSomethingAboutIt)
. It's an important feature that we're lacking so I'm flagging this as a feature request instead of considering it a bug in our module (it's more of a bug).
what exact type of connection error are you trying to detect?
Is there a way to detect connection/communication errors?
there's no way to detect disconnect.
sometimes Node.JS TCP/HTTP or other TCP libraries will consider an unexpected client disconnect as "connection error". These connection "errors" are deliberately ignored by the library and sockets are designed to gracefully attempt reconnections without surfacing anything like err to application
Thank you for your answer @reqshark. Graceful reconnection attempts are a good thing but I think that an optional maximum number of reconnection attempts which, once reached, gives an error, could be interesting. This way, the UI or client can have a clue that something is not correctly working (take as an example an attempt to connect to an unknown host).
Hi,
Is there a way to detect connection/communication errors? For example, it seems like
connect()
should return a negative integer on failure, but the following always return1
:I also tried to listen for errors:
But it never fires, so what is the proper way to catch connection/communication errors?