1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-28 05:03:59 +03:00

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.
This commit is contained in:
Erik Johnston
2016-09-22 16:24:40 +01:00
parent 3a17ef983e
commit 352f79e9fd

View File

@@ -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 });
}
});
};