saghul / node-abstractsocket

Abstract namespace socket support for Node
MIT License
24 stars 13 forks source link

Socket.emit error alwasy crash the caller #16

Closed japita-se closed 5 years ago

japita-se commented 5 years ago

I found that this line: setImmediate(() => sock.emit('error', errnoException(err, 'connect')));

always crashes the client, even if it is wrapped inside a try-catch block. I found that putting another name, e.g. setImmediate(() => sock.emit('my error', errnoException(err, 'connect'))); everything is fine, i.e. I can catch the error.

saghul commented 5 years ago

What do you mean? Can you show a trace? Note that the error is fatal, so you can't just catch it and move on.

You can listen to the error event on the socket and act on it.

japita-se commented 5 years ago

If the server the socket is trying to connect to is not responding how shall I catch the error? The following error is never fired.

client.on('error', function(err) {                
                    logger.error("AVRO","Error ",err);
});
saghul commented 5 years ago

I'm not sure the connect fails when there is no server, TBH.