Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling error in connectSocket #53

Closed
vjocw opened this issue May 14, 2020 · 5 comments
Closed

Handling error in connectSocket #53

vjocw opened this issue May 14, 2020 · 5 comments

Comments

@vjocw
Copy link

vjocw commented May 14, 2020

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
Copy link
Author

vjocw commented May 18, 2020

@pocesar Following up on this.

@pocesar
Copy link
Owner

pocesar commented May 18, 2020

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
Copy link
Author

vjocw commented May 19, 2020

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

@pocesar
Copy link
Owner

pocesar commented May 19, 2020

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

@vjocw
Copy link
Author

vjocw commented May 19, 2020

@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.

@vjocw vjocw closed this as completed May 19, 2020
gopherbot pushed a commit to golang/vscode-go that referenced this issue Jun 12, 2020
json-rpc2 module doesn't catch all the errors in its callback. If a remote connection fails to be established, it won't call the callback for errors. So the connection will hang. There are no future plans to handle the error case through the callback: json-rpc2: pocesar/node-jsonrpc2#53. Node.js handles errors in a similar way: https://nodejs.org/api/net.html#net_socket_connect. Errors won't be exposed through the callback, only through the error listener.

Fixes #215

Change-Id: I75cfb2a0cf6628a8c35ddccf8c96ec1ade0275f1
GitHub-Last-Rev: 44d9b59
GitHub-Pull-Request: #216
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/237559
Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants