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 #5

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Error handling #5

wants to merge 4 commits into from

Conversation

mrtcode
Copy link
Member

@mrtcode mrtcode commented Jul 6, 2017

This is only the initial version of how the new error handling could look like. This update utilizes zotero/stream-server#8 , which no longer closes the connection on error, but instead returns it as an error event with a message, code and requestID. This update allows to just use a callback function when creating a subscription, and the function is called when a message from stream-server is received with the same requestID. Currently implemented only for subscription creation.

'Reconnect on any error' commit makes zotero-api-node/stream.js to handle connection errors (i.e. ECONNREFUSED) by itself, instead of allowing them to bubble up to arkivo and crash the process. This is not ideal, because arkivo no longer know about errors inside stream.js. But connection error handler should be wrapped by reconnect logic, and currently the reconnect is handled inside stream.js (zotero-api-node). But for now it's still better than allowing process to crash on typical connection errors.

lib/stream.js Outdated
@@ -463,7 +495,7 @@ Stream.prototype.error = function (error) {
error = new Error(format.apply(null, arguments));

debug(error.message);
this.emit('error', error);
this.socket.close();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only a temporary solution. Need to investigate how to reliably trigger closed function when an error occurs.

@mrtcode mrtcode mentioned this pull request Jul 6, 2017
@mrtcode
Copy link
Member Author

mrtcode commented Jul 7, 2017

So, I think we should use node_redis as an example for error handling. It automatically reconnects and even resubscribes to channels, but it always emits an error event on any connection failure, and if it's not handled then the process will crash. But if handled, Redis will reconnect.

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

Successfully merging this pull request may close these issues.

None yet

1 participant