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

Emit and Publish Peer Connection Errors #312

Closed
wants to merge 5 commits into from
Closed

Emit and Publish Peer Connection Errors #312

wants to merge 5 commits into from

Conversation

wooliet
Copy link
Contributor

@wooliet wooliet commented May 17, 2016

A zetta instance's pubsub can be used to react to peer client disconnect events. Currently, the peer_client module will emit a "closed" event for both error and close events.

peer_client

self.ws.on('error', function onError(err) {
   //...
  self.emit('closed');
});

The following zetta handle of "error" events (and it publish of a "disconnect" topic) will never be called.

peerClient.on('error', function(error) {
  self.peerRegistry.get(peer.id, function(err, result) {
    result.status = 'failed';
    result.error = error;
    result.connectionId = peerClient.connectionId;
    self.peerRegistry.save(result);

    // peer-event
    self.pubsub.publish('_peer/disconnect', { peer: peerClient });
  });
});

This PR adds emit('error', err) to the peer_client module, and updates the zetta handler to publish a '_peer/error' topic with the error and peerClient objects.

It is not expected to cause issues with current code because the "error" event handler was previously never called.

William King added 2 commits May 17, 2016 12:39
A zetta instance's `pubsub` can be used to react to peer client
disconnect events. Currently, the _peer_client_ module will emit a
"closed" event for both a socket error *and* socket close event. This
means the zetta handle of 'error' events will never be called.

This change adds `emit('error', err)` to the _peer_client_ module, and
updates _zetta_ to publish the '_peer/disconnect' event with the
`error` object as an additional property of the published data.

`publish('_peer/disconnect'), {peer:peerClient, error: error});`

This allows code that subscribes to the peer disconnect events to
react specifically to errors.
Updated _zetta_ module to publish '_peer/error' instead of disconnect
on a peer client 'error' event. This should not cause an issues with
existing code because the 'error' event was previously never emitted.
@AdamMagaluk
Copy link
Collaborator

Hi @wooliet,

To start i'd be interested in why and what information you're currently lacking with zetta? Is it just the error message to see why it failed?

I have a concerns about adding another _peer/<event> type of event.

  1. When the peer_client disconnects with an error the peer registry will be in an intermittent state. Since in zetta.js we're looking for both closed and error and updating the registry i'm not sure what will always end up in the registry in this case because we're emitting both the events. Code Here
  2. If we add the _peer/error event we may need to add it the events that are sent over the /peer-management websocket endpoint. Would it feel strange for a client to receive a disconnect and an error event? Code Here
  3. Thinking about the other direction peers connecting to a cloud. Should the cloud zetta also emit a _peer/error event when the peer_socket emits an error? Code Here

I would like to propose an alternative approach. Have the peer_client emit only the error event when the underlying websocket emits error. In zetta.js still have it emit _peer/disconnect but with an additional error property on the object that's emitted. This will keep the peer-management api and our events the same but provide the additional info as well as address the issue that the peer_clients error event is never emitted and thus the registry never says the peer went into a failed state.

@wooliet
Copy link
Contributor Author

wooliet commented May 18, 2016

@AdamMagaluk

I have a zetta instance "linked" to another. When the main instance restarts and has a new location, I want to be sure and trigger a reconnect process for the original. When the instance tries to connect to a bad location, the ultimate error is "ECONNREFUSED". I wanted to handle that specific issue.

  1. "Emitting both events": Are you sure you're emitting both? I am pretty certain that the peer client error handler is never called (looking here). I scanned a few unit tests but (to be honest) did not spend the time to create one that would confirm this behavior. If the peer registry state is working as expected now, it might be a side-effect of something else, and not because the error handler is executed.
  2. "Peer Management": Receiving two distinct events would not feel strange. But it also makes sense to indicate that the disconnect was triggered by an error by including an error with the event data.
  3. "Peers to Cloud": Same as above.

"Alternative Approach": Your suggestion is the same as my first pass at this. But when I realized that the "error" event is never actually emitted by peer_client, it seemed cleaner to me to publish a unique topic as opposed adding additional data to existing topics.

@AdamMagaluk
Copy link
Collaborator

Regarding 1. Today we are only emitting closed. My proposal would be to have it emit only error here. My concern was that in your PR we are now emitting both here which would lead to both of the handlers in zetta.js to be called at the same time. here

@AdamMagaluk
Copy link
Collaborator

@wooliet This is kinda what i'm thinking. 6206dc5

@wooliet
Copy link
Contributor Author

wooliet commented May 18, 2016

@AdamMagaluk Yeah, that looks right. I agree it'd be better to not emit both "closed" and "error".

I don't know the implications of adding the error data in event_socket.

@AdamMagaluk
Copy link
Collaborator

The small update i made in event_socket would allow ws clients subscribed to /peer-management to see if an error occurred on disconnect. Because we can't send the entire peerClient down the websocket we override the actual data with peerClients.properties() but that doesn't included the error parameter.

@AdamMagaluk
Copy link
Collaborator

@wooliet Would you want to include that one small change in event_socket then i'd be happy to get this PR merged in.

@wooliet
Copy link
Contributor Author

wooliet commented May 27, 2016

I'm sorry @AdamMagaluk , I missed this.

What specific changes would you like for me to add? Those you linked to in lib/event_socket.js?

@AdamMagaluk
Copy link
Collaborator

@wooliet Would be the changes in evet_socket from this branch. 6206dc5

@AdamMagaluk
Copy link
Collaborator

+1

1 similar comment
@mdobson
Copy link
Contributor

mdobson commented Jun 14, 2016

+1

@AdamMagaluk
Copy link
Collaborator

Closing but opened new PR with commits and tests. #317

AdamMagaluk added a commit that referenced this pull request Jun 14, 2016
* Emit & Publish Peer Connection Errors

A zetta instance's `pubsub` can be used to react to peer client
disconnect events. Currently, the _peer_client_ module will emit a
"closed" event for both a socket error *and* socket close event. This
means the zetta handle of 'error' events will never be called.

This change adds `emit('error', err)` to the _peer_client_ module, and
updates _zetta_ to publish the '_peer/disconnect' event with the
`error` object as an additional property of the published data.

`publish('_peer/disconnect'), {peer:peerClient, error: error});`

This allows code that subscribes to the peer disconnect events to
react specifically to errors.

* Publish Error

Updated _zetta_ module to publish '_peer/error' instead of disconnect
on a peer client 'error' event. This should not cause an issues with
existing code because the 'error' event was previously never emitted.

* Update _peer_client_ to only emit the "error" event.

#312 (comment)

* Updated PR per @AdamMagaluk; changes to match _event_socket_ in:

6206dc5

* Added tests to ensure PeerClients emits the proper close event

* Remove use of _peer/error and use only _peer/disconnect
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

Successfully merging this pull request may close these issues.

3 participants