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

Don't emit ERROR until a keepalive poke fails

This accomplishes the same as
https://github.com/matrix-org/matrix-js-sdk/pull/216/files, but
without the client waiting 110 seconds for a sync request to time
out. That is, don't display an error message a soon as a sync
request fails, since we should accept that sometimes long lived
HTTP connections will go away and that's fine.

Also:
 * Use request rather than deprecated requestWithPrefix
 * http-api: The empty string may be falsy, but it's a valid prefix
This commit is contained in:
David Baker
2016-10-06 18:29:05 +01:00
parent 57cf7e1f7d
commit 1c744a66e6
2 changed files with 26 additions and 8 deletions

View File

@@ -351,7 +351,7 @@ module.exports.MatrixHttpApi.prototype = {
*/
request: function(callback, method, path, queryParams, data, opts) {
opts = opts || {};
var prefix = opts.prefix || this.opts.prefix;
var prefix = opts.prefix !== undefined ? opts.prefix : this.opts.prefix;
var fullUri = this.opts.baseUrl + prefix + path;
return this.requestOtherUrl(

View File

@@ -406,7 +406,7 @@ SyncApi.prototype.sync = function() {
self._sync({ filterId: filterId });
}, function(err) {
self._startKeepAlives().done(function() {
self._startKeepAlives(0).done(function() {
getFilter();
});
self._updateSyncState("ERROR", { error: err });
@@ -546,12 +546,17 @@ SyncApi.prototype._sync = function(syncOptions) {
console.error(err);
debuglog("Starting keep-alive");
self._syncConnectionLost = true;
self._startKeepAlives().done(function() {
// Note that we do *not* mark the sync connection as
// lost yet: we only do this if a keepalive poke
// fails, since long lived HTTP connections will
// go away sometimes and we shouldn't treat this as
// erroneous.
// We sent the first keep alive immediately because
// of this.
self._startKeepAlives(0).done(function() {
self._sync(syncOptions);
});
self._currentSyncRequest = null;
self._updateSyncState("ERROR", { error: err });
});
};
@@ -874,9 +879,15 @@ SyncApi.prototype._pokeKeepAlive = function() {
}
}
this.client._http.requestWithPrefix(
undefined, "GET", "/_matrix/client/versions", undefined,
undefined, "", 15 * 1000
this.client._http.request(
undefined, // callback
"GET", "/_matrix/client/versions",
undefined, // queryParams
undefined, // data
{
prefix: '',
localTimeoutMs: 15 * 1000,
}
).done(function() {
success();
}, function(err) {
@@ -888,6 +899,13 @@ SyncApi.prototype._pokeKeepAlive = function() {
// responses fail, this will mean we don't hammer in a loop.
self._keepAliveTimer = setTimeout(success, 2000);
} else {
// If we haven't already marked this sync
// connection as gone-away, do so now and
// emit an error.
if (!self._syncConnectionLost) {
self._syncConnectionLost = true;
self._updateSyncState("ERROR", { error: err });
}
self._keepAliveTimer = setTimeout(
self._pokeKeepAlive.bind(self),
5000 + Math.floor(Math.random() * 5000)