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

Network error handling #226

Merged
merged 9 commits into from
Jun 8, 2017
Merged

Network error handling #226

merged 9 commits into from
Jun 8, 2017

Conversation

stafyniaksacha
Copy link
Contributor

@stafyniaksacha stafyniaksacha commented Jun 1, 2017

Bugfixes

  • SocketIO: handle network errors (like we do in Websocket protocol wrapper)
  • Websocket: arguments can differs from NodeJS and Browsers
  • Auto resubscribe when a reconnection occurs after a network error

@codecov-io
Copy link

codecov-io commented Jun 7, 2017

Codecov Report

Merging #226 into 5.x will increase coverage by 0.3%.
The diff coverage is 98.59%.

Impacted file tree graph

@@            Coverage Diff            @@
##              5.x     #226     +/-   ##
=========================================
+ Coverage   98.24%   98.54%   +0.3%     
=========================================
  Files          17       17             
  Lines        2050     2408    +358     
  Branches      590      714    +124     
=========================================
+ Hits         2014     2373    +359     
+ Misses         36       35      -1
Impacted Files Coverage Δ
src/Kuzzle.js 98.94% <100%> (+0.19%) ⬆️
src/Room.js 100% <100%> (ø) ⬆️
src/networkWrapper/wrappers/socketio.js 100% <100%> (ø) ⬆️
src/networkWrapper/wrappers/websocket.js 98.7% <95.45%> (-1.3%) ⬇️
src/security/User.js 98.78% <0%> (+0.01%) ⬆️
src/MemoryStorage.js 99.41% <0%> (+0.39%) ⬆️
src/security/Security.js 98.25% <0%> (+0.52%) ⬆️
src/Collection.js 97.94% <0%> (+1.08%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ec13b7f...30064fe. Read the comment docs.

@ballinette
Copy link

missing description of what is the issue this PR fixes ?

Copy link
Contributor

@benoitvidis benoitvidis left a comment

Choose a reason for hiding this comment

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

Can you provide some information about this PR (context, issue, what is the problem and what it solves?)

this.socket = window.io((this.ssl ? 'https://' : 'http://') + this.host + ':' + this.port, {
reconnection: autoReconnect,
reconnectionDelay: reconnectionDelay,
forceNew: true
});

this.socket.on('connect', function() {
if (self.wasConnected) {
Copy link
Contributor

Choose a reason for hiding this comment

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

According to socket.io documentation, connect event is fired "upon a connection including a successful reconnection".
If this is the case, don't we have a double trigger with the on('reconnect',..) one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, this is different cases:

  • reconnection on connect event is used when proxy close connection
  • reconnection on reconnect event is used when socket hang out and come back again via socket io reconnection logic

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, I see that you intend to use them differently but this is not what the doc says. connect is fired each time a connection is made, including socket.io reconnections.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, so I removed reconnect listener

self.retrying = false;
self.connect(autoReconnect, reconnectionDelay);
}, reconnectionDelay);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't this part supposed to be natively handled by socket.io reconnect options?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know why but reconnection from socketio does not work... (love socketio <3)

Copy link
Contributor

Choose a reason for hiding this comment

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

Hum.. If this is the case, shouldn't we then just not use it at all?
If it happens to work as expected, I still see an double trigger issue btw the connect and reconnect handlers (latest never being fired).

@stafyniaksacha stafyniaksacha changed the title Network error handling Disconnect client when no backend left Jun 7, 2017
@stafyniaksacha stafyniaksacha changed the title Disconnect client when no backend left Network error handling Jun 7, 2017
@stafyniaksacha
Copy link
Contributor Author

stafyniaksacha commented Jun 7, 2017

@ballinette @benoitvidis sorry for the description, I haven't saved it ^^

src/Room.js Outdated
subscribeQuery = self.kuzzle.addHeaders(subscribeQuery, this.headers);
subscribeQuery = self.kuzzle.addHeaders(subscribeQuery, self.headers);

networkListener = function() {

Choose a reason for hiding this comment

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

I don't like this behaviour (too many "addListener" and "removeListener").

Better just add following lines into src/Kuzzle.js (at line 365) :

self.network.onConnectError(function (error) {
// (...)
  disableAllSubscriptions.call(self);
// (...)
});

function disableAllSubscriptions() {
  var self = this;

  Object.keys(self.subscriptions).forEach(function (roomId) {
    Object.keys(self.subscriptions[roomId]).forEach(function (subscriptionId) {
      var subscription = self.subscriptions[roomId][subscriptionId];
      subscription.subscribing = false;
    });
  });
}

It should work, but without a complex listener management.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Work like a charm !

this.socket = window.io((this.ssl ? 'https://' : 'http://') + this.host + ':' + this.port, {
reconnection: autoReconnect,
reconnectionDelay: reconnectionDelay,
forceNew: true
});

this.socket.on('connect', function() {
if (self.wasConnected) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Well, I see that you intend to use them differently but this is not what the doc says. connect is fired each time a connection is made, including socket.io reconnections.

self.retrying = false;
self.connect(autoReconnect, reconnectionDelay);
}, reconnectionDelay);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Hum.. If this is the case, shouldn't we then just not use it at all?
If it happens to work as expected, I still see an double trigger issue btw the connect and reconnect handlers (latest never being fired).

@xbill82 xbill82 merged commit d63b2cb into 5.x Jun 8, 2017
@xbill82 xbill82 deleted the network-error-handling branch June 8, 2017 15:58
@scottinet scottinet mentioned this pull request Jun 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants