Permalink
Browse files

Also clear heartbeat timer when we get data messages.

This fixes an issue with spurious connection closing.
  • Loading branch information...
n1mmy committed Jun 12, 2012
1 parent d08b53a commit 604977120488e2963abd82c4d9dffee85a5e711c
Showing with 13 additions and 12 deletions.
  1. +13 −12 packages/stream/stream_client.js
@@ -162,11 +162,7 @@ _.extend(Meteor._Stream.prototype, {
clearTimeout(self.connection_timer);
self.connection_timer = null;
}
- if (self.heartbeat_timer)
- clearTimeout(self.heartbeat_timer);
- self.heartbeat_timer = setTimeout(
- _.bind(self._heartbeat_timeout, self),
- self.HEARTBEAT_TIMEOUT);
+ self._heartbeat_received();
if (self.current_status.connected) {
@@ -247,6 +243,15 @@ _.extend(Meteor._Stream.prototype, {
self._fake_connect_failed();
},
+ _heartbeat_received: function () {
+ var self = this;
+ if (self.heartbeat_timer)
+ clearTimeout(self.heartbeat_timer);
+ self.heartbeat_timer = setTimeout(
+ _.bind(self._heartbeat_timeout, self),
+ self.HEARTBEAT_TIMEOUT);
+ },
+
_retry_timeout: function (count) {
var self = this;
@@ -321,6 +326,8 @@ _.extend(Meteor._Stream.prototype, {
Meteor._debug("Exception while processing message", e.stack);
}
});
+
+ self._heartbeat_received();
};
self.socket.onclose = function () {
// Meteor._debug("stream disconnect", _.toArray(arguments), (new Date()).toDateString());
@@ -332,13 +339,7 @@ _.extend(Meteor._Stream.prototype, {
};
self.socket.onheartbeat = function () {
- // reset heartbeat timer when we get a heartbeat.
- if (self.heartbeat_timer) {
- clearTimeout(self.heartbeat_timer);
- self.heartbeat_timer = setTimeout(
- _.bind(self._heartbeat_timeout, self),
- self.HEARTBEAT_TIMEOUT);
- }
+ self._heartbeat_received();
};
if (self.connection_timer)

0 comments on commit 6049771

Please sign in to comment.