pocesar/node-jsonrpc2

Handling error in connectSocket

vjocw opened this issue · 5 comments

vjocw commented

Hello,

We are developing a dependency that uses your library and we came across a problem where a connection hangs. I dived more deeply into the problem and noticed that in the connectSocket in json-rpc2 function does not call the callback when net.connection errors out. Please see the below code for connectSocket. Was this intentional? In my testing, if I put this code block under L163, everything works as expected:

conn.on('error', (error) => {
     callback(error);
});

Happy to send out a Pull Request. Please let me know.

connectSocket:
https://github.com/pocesar/node-jsonrpc2/blob/master/src/client.js#L144

conn:
https://github.com/pocesar/node-jsonrpc2/blob/master/src/client.js#L162

vjocw commented

@pocesar Following up on this.

hey @vincentjocodes yes, it's a bug, the code for errors is not consistent #3 #2 #46

since it was going to have a refactor before, and were stalled, it didn't went through. I' think there are other places where the error should be forwarded to the event listener is broken as well

vjocw commented

@pocesar Is there a plan to do a refactor or have a fix out?

@vincentjocodes not in the near future 😞 the refactor is going to be in Typescript

vjocw commented

@pocesar Okay, thank you letting me know, I will see if the user of this package will handle errors from the object being returned rather than through the callback.