You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2026-01-03 23:22:30 +03:00
Fix bug where hibernating laptops fail to restart the event stream.
On some devices, the act of hibernating black holes the request so the success/failure callbacks never fire. This prevents a re-poll as that is done in the callbacks. To fix this, we add a local timer which, when it fires, will forcibly do a re-poll. The local timer has a timeout value several seconds more than the timeout= value (which should've returned by then).
This commit is contained in:
@@ -1053,10 +1053,22 @@ function _pollForEvents(client) {
|
||||
if (!client.clientRunning) {
|
||||
return;
|
||||
}
|
||||
var discardResult = false;
|
||||
var timeoutObj = setTimeout(function() {
|
||||
discardResult = true;
|
||||
_pollForEvents(client);
|
||||
}, 40000);
|
||||
|
||||
client._http.authedRequest(undefined, "GET", "/events", {
|
||||
from: client.fromToken,
|
||||
timeout: 30000
|
||||
}).done(function(data) {
|
||||
if (discardResult) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
clearTimeout(timeoutObj);
|
||||
}
|
||||
var events = [];
|
||||
if (data) {
|
||||
events = utils.map(data.chunk, function(event) {
|
||||
@@ -1120,6 +1132,12 @@ function _pollForEvents(client) {
|
||||
}
|
||||
_pollForEvents(self);
|
||||
}, function(err) {
|
||||
if (discardResult) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
clearTimeout(timeoutObj);
|
||||
}
|
||||
self.emit("syncError", err);
|
||||
// retry every few seconds
|
||||
// FIXME: this should be exponential backoff with an option to nudge
|
||||
|
||||
Reference in New Issue
Block a user