You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-09-04 19:42:11 +03:00
Remove low client-side timeouts hack
This commit is contained in:
30
lib/sync.js
30
lib/sync.js
@@ -66,7 +66,6 @@ function SyncApi(client, opts) {
|
|||||||
opts.pendingEventOrdering = opts.pendingEventOrdering || "chronological";
|
opts.pendingEventOrdering = opts.pendingEventOrdering || "chronological";
|
||||||
this.opts = opts;
|
this.opts = opts;
|
||||||
this._peekRoomId = null;
|
this._peekRoomId = null;
|
||||||
this._lowClientTimeouts = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -276,7 +275,7 @@ SyncApi.prototype.sync = function() {
|
|||||||
attempt += 1;
|
attempt += 1;
|
||||||
|
|
||||||
client.getPushRules().done(function(result) {
|
client.getPushRules().done(function(result) {
|
||||||
console.log("Got push rules");
|
debuglog("Got push rules");
|
||||||
client.pushRules = result;
|
client.pushRules = result;
|
||||||
getFilter(); // Now get the filter
|
getFilter(); // Now get the filter
|
||||||
}, retryHandler(attempt, getPushRules));
|
}, retryHandler(attempt, getPushRules));
|
||||||
@@ -349,25 +348,10 @@ SyncApi.prototype._sync = function(syncOptions, attempt) {
|
|||||||
// normal timeout= plus buffer time
|
// normal timeout= plus buffer time
|
||||||
var clientSideTimeoutMs = this.opts.pollTimeout + BUFFER_PERIOD_MS;
|
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(
|
client._http.authedRequestWithPrefix(
|
||||||
undefined, "GET", "/sync", qps, undefined, httpApi.PREFIX_V2_ALPHA,
|
undefined, "GET", "/sync", qps, undefined, httpApi.PREFIX_V2_ALPHA,
|
||||||
clientSideTimeoutMs
|
clientSideTimeoutMs
|
||||||
).done(function(data) {
|
).done(function(data) {
|
||||||
debuglog("DEBUG[%s]: _sync RECV", dateStamp);
|
|
||||||
self._lowClientTimeouts = false;
|
|
||||||
// data looks like:
|
// data looks like:
|
||||||
// {
|
// {
|
||||||
// next_batch: $token,
|
// next_batch: $token,
|
||||||
@@ -541,16 +525,10 @@ SyncApi.prototype._sync = function(syncOptions, attempt) {
|
|||||||
|
|
||||||
self._sync(syncOptions);
|
self._sync(syncOptions);
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
debuglog("DEBUG[%s]: RECV FAIL %s", dateStamp, require("util").inspect(err));
|
|
||||||
console.error("/sync error (%s attempts): %s", attempt, err);
|
console.error("/sync error (%s attempts): %s", attempt, err);
|
||||||
console.error(err);
|
console.error(err);
|
||||||
attempt += 1;
|
attempt += 1;
|
||||||
startSyncingRetryTimer(client, attempt, function(newAttempt, extendedWait) {
|
startSyncingRetryTimer(client, attempt, function(newAttempt) {
|
||||||
debuglog("DEBUG[%s]: Init new _sync new_attempt=%s extended_wait=%s",
|
|
||||||
dateStamp, newAttempt, extendedWait);
|
|
||||||
if (extendedWait) {
|
|
||||||
self._lowClientTimeouts = true;
|
|
||||||
}
|
|
||||||
self._sync(syncOptions, newAttempt);
|
self._sync(syncOptions, newAttempt);
|
||||||
});
|
});
|
||||||
updateSyncState(client, "ERROR", { error: err });
|
updateSyncState(client, "ERROR", { error: err });
|
||||||
@@ -745,19 +723,17 @@ function startSyncingRetryTimer(client, attempt, fn) {
|
|||||||
client._syncingRetry.timeoutId = setTimeout(function() {
|
client._syncingRetry.timeoutId = setTimeout(function() {
|
||||||
var timeAfterWaitingMs = Date.now();
|
var timeAfterWaitingMs = Date.now();
|
||||||
var timeDeltaMs = timeAfterWaitingMs - timeBeforeWaitingMs;
|
var timeDeltaMs = timeAfterWaitingMs - timeBeforeWaitingMs;
|
||||||
var extendedWait = false;
|
|
||||||
if (timeDeltaMs > (2 * timeToWaitMs)) {
|
if (timeDeltaMs > (2 * timeToWaitMs)) {
|
||||||
// we've waited more than twice what we were supposed to. Reset the
|
// 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
|
// attempt number back to 1. This can happen when the comp goes to
|
||||||
// sleep whilst the timer is running.
|
// sleep whilst the timer is running.
|
||||||
newAttempt = 1;
|
newAttempt = 1;
|
||||||
extendedWait = true;
|
|
||||||
console.warn(
|
console.warn(
|
||||||
"Sync retry timer: Tried to wait %s ms but actually waited %s ms",
|
"Sync retry timer: Tried to wait %s ms but actually waited %s ms",
|
||||||
timeToWaitMs, timeDeltaMs
|
timeToWaitMs, timeDeltaMs
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
fn(newAttempt, extendedWait);
|
fn(newAttempt);
|
||||||
}, timeToWaitMs);
|
}, timeToWaitMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user