diff --git a/lib/client.js b/lib/client.js index bccbe38e8..ea4f2339e 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1878,8 +1878,10 @@ MatrixClient.prototype.isLoggedIn = function() { * @param {MatrixClient} client * @param {integer} historyLen * @param {integer} includeArchived + * @param {integer} attempt */ -function doInitialSync(client, historyLen, includeArchived) { +function doInitialSync(client, historyLen, includeArchived, attempt) { + attempt = attempt || 1; var qps = { limit: historyLen }; if (includeArchived) { qps.archived = true; @@ -1980,8 +1982,12 @@ function doInitialSync(client, historyLen, includeArchived) { client.emit("syncComplete"); _pollForEvents(client); }, function(err) { - console.error("/initialSync error: %s", err); + console.error("/initialSync error (%s attempts): %s", attempt, err); client.emit("syncError", err); + attempt += 1; + setTimeout(function() { + doInitialSync(client, historyLen, includeArchived, attempt); + }, Math.pow(2, Math.min(attempt, 7)) * 1000); // max 2^7 secs = 2.1 mins // TODO: Retries. }); }