From 352f79e9fd02e5626b8b3945ce956aa609ac765d Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 22 Sep 2016 16:24:40 +0100 Subject: [PATCH] Handle the first /sync failure differently. A /sync request may spuriously fail on occasion, without the "connection" actually being lost. To avoid spurious "Connection Lost" warning messages we ignore the first /sync and immediately retry, and only if that fails do we enter an ERROR state. --- lib/sync.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/sync.js b/lib/sync.js index f1581cd32..dea2feb28 100644 --- a/lib/sync.js +++ b/lib/sync.js @@ -545,13 +545,22 @@ SyncApi.prototype._sync = function(syncOptions) { console.error("/sync error %s", err); console.error(err); - debuglog("Starting keep-alive"); - self._syncConnectionLost = true; - self._startKeepAlives().done(function() { + if (!self._syncConnectionLost) { + // This is the first failure, which may be spurious. To avoid unnecessary + // connection error warnings we simply retry the /sync immediately. Only + // if *that* one fails too do we say the connection has been lost. + // Should we emit a state like "MAYBE_CONNETION_LOST"? + self._syncConnectionLost = true; self._sync(syncOptions); - }); - self._currentSyncRequest = null; - self._updateSyncState("ERROR", { error: err }); + } else { + debuglog("Starting keep-alive"); + self._syncConnectionLost = true; + self._startKeepAlives().done(function() { + self._sync(syncOptions); + }); + self._currentSyncRequest = null; + self._updateSyncState("ERROR", { error: err }); + } }); };