diff --git a/lib/client.js b/lib/client.js index f23fb4a69..d44c21e63 100644 --- a/lib/client.js +++ b/lib/client.js @@ -2150,16 +2150,23 @@ function _pollForEvents(client, attempt) { if (!client.clientRunning) { return; } + var timeoutMs = client._config.pollTimeout; + if (attempt > 1) { + // we think the connection is dead. If it comes back up, we won't know + // about it till /events returns. If the timeout= is high, this could + // be a long time. Set it to 1 when doing retries. + timeoutMs = 1; + } var discardResult = false; var timeoutObj = setTimeout(function() { discardResult = true; console.error("/events request timed out."); _pollForEvents(client); - }, client._config.pollTimeout + (20 * 1000)); // 20s buffer + }, timeoutMs + (20 * 1000)); // 20s buffer client._http.authedRequest(undefined, "GET", "/events", { from: client.store.getSyncToken(), - timeout: client._config.pollTimeout + timeout: timeoutMs }).done(function(data) { if (discardResult) { return;