From cca5edd40eeb81a5dad69d6fec0db45307e16046 Mon Sep 17 00:00:00 2001 From: Graham Hughes Date: Wed, 10 Jun 2015 12:37:04 -0700 Subject: [PATCH] Clear and reset all relevant timers on packet Not clear to me that receiving a pong would actually clear the old heartbeat timer. --- packages/ddp-common/heartbeat.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/ddp-common/heartbeat.js b/packages/ddp-common/heartbeat.js index f6bd27a114..31c400340a 100644 --- a/packages/ddp-common/heartbeat.js +++ b/packages/ddp-common/heartbeat.js @@ -79,24 +79,30 @@ _.extend(DDPCommon.Heartbeat.prototype, { self._onTimeout(); }, - pingReceived: function () { + // Restart all timers, as we got a message from the counterparty. + _restartTimers: function () { var self = this; - // We know the connection is alive if we receive a ping, so we - // don't need to send a ping ourselves. Reset the interval timer. + if (self._heartbeatTimeoutHandle) { + self._clearHeartbeatTimeoutTimer(); + } if (self._heartbeatIntervalHandle) { self._clearHeartbeatIntervalTimer(); self._startHeartbeatIntervalTimer(); } }, + pingReceived: function () { + var self = this; + // We know the connection is alive if we receive a ping, so we + // don't need to send a ping ourselves. Reset the interval timer. + self._restartTimers(); + }, + pongReceived: function () { var self = this; // Receiving a pong means we won't timeout, so clear the timeout // timer and start the interval again. - if (self._heartbeatTimeoutHandle) { - self._clearHeartbeatTimeoutTimer(); - self._startHeartbeatIntervalTimer(); - } + self._restartTimers(); } });