1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-09-01 21:21:58 +03:00

Remove low client-side timeouts hack

This commit is contained in:
Kegan Dougal
2016-01-21 16:12:07 +00:00
parent 4bc2869522
commit ff990914b2

View File

@@ -66,7 +66,6 @@ function SyncApi(client, opts) {
opts.pendingEventOrdering = opts.pendingEventOrdering || "chronological";
this.opts = opts;
this._peekRoomId = null;
this._lowClientTimeouts = false;
}
/**
@@ -276,7 +275,7 @@ SyncApi.prototype.sync = function() {
attempt += 1;
client.getPushRules().done(function(result) {
console.log("Got push rules");
debuglog("Got push rules");
client.pushRules = result;
getFilter(); // Now get the filter
}, retryHandler(attempt, getPushRules));
@@ -349,25 +348,10 @@ SyncApi.prototype._sync = function(syncOptions, attempt) {
// normal timeout= plus buffer time
var clientSideTimeoutMs = this.opts.pollTimeout + BUFFER_PERIOD_MS;
if (self._lowClientTimeouts) {
debuglog("_lowClientTimeouts flag set.");
clientSideTimeoutMs = this.opts.pollTimeout;
}
var dateStamp = new Date();
dateStamp = dateStamp.getHours() + ":" + dateStamp.getMinutes() + ":" +
dateStamp.getSeconds() + "." + dateStamp.getMilliseconds();
debuglog("DEBUG[%s]: NEW _sync attempt=%s qp_timeout=%s cli_timeout=%s",
dateStamp, attempt, qps.timeout, clientSideTimeoutMs);
client._http.authedRequestWithPrefix(
undefined, "GET", "/sync", qps, undefined, httpApi.PREFIX_V2_ALPHA,
clientSideTimeoutMs
).done(function(data) {
debuglog("DEBUG[%s]: _sync RECV", dateStamp);
self._lowClientTimeouts = false;
// data looks like:
// {
// next_batch: $token,
@@ -541,16 +525,10 @@ SyncApi.prototype._sync = function(syncOptions, attempt) {
self._sync(syncOptions);
}, function(err) {
debuglog("DEBUG[%s]: RECV FAIL %s", dateStamp, require("util").inspect(err));
console.error("/sync error (%s attempts): %s", attempt, err);
console.error(err);
attempt += 1;
startSyncingRetryTimer(client, attempt, function(newAttempt, extendedWait) {
debuglog("DEBUG[%s]: Init new _sync new_attempt=%s extended_wait=%s",
dateStamp, newAttempt, extendedWait);
if (extendedWait) {
self._lowClientTimeouts = true;
}
startSyncingRetryTimer(client, attempt, function(newAttempt) {
self._sync(syncOptions, newAttempt);
});
updateSyncState(client, "ERROR", { error: err });
@@ -745,19 +723,17 @@ function startSyncingRetryTimer(client, attempt, fn) {
client._syncingRetry.timeoutId = setTimeout(function() {
var timeAfterWaitingMs = Date.now();
var timeDeltaMs = timeAfterWaitingMs - timeBeforeWaitingMs;
var extendedWait = false;
if (timeDeltaMs > (2 * timeToWaitMs)) {
// we've waited more than twice what we were supposed to. Reset the
// attempt number back to 1. This can happen when the comp goes to
// sleep whilst the timer is running.
newAttempt = 1;
extendedWait = true;
console.warn(
"Sync retry timer: Tried to wait %s ms but actually waited %s ms",
timeToWaitMs, timeDeltaMs
);
}
fn(newAttempt, extendedWait);
fn(newAttempt);
}, timeToWaitMs);
}