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

Error handling #203

Open
jonathan-roy opened this issue Mar 31, 2019 · 3 comments
Open

Error handling #203

jonathan-roy opened this issue Mar 31, 2019 · 3 comments

Comments

@jonathan-roy
Copy link

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 return 1:

const nano = require("nanomsg");

const socket = nano.socket("req");
const ret = socket.connect("ws://anything");
console.log(ret); // Always `1`

I also tried to listen for errors:

socket.on("error", (err) => console.log(err)); // Never fired

But it never fires, so what is the proper way to catch connection/communication errors?

@reqshark
Copy link
Collaborator

reqshark commented Apr 6, 2019

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

@reqshark
Copy link
Collaborator

reqshark commented Apr 6, 2019

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

@jonathan-roy
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants