You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-28 05:03:59 +03:00
Respond to code review
- failedSyncCount -> this._failedSyncCount - Reset at a point which is more obviously after a successful sync, and add comments to clarify the recursive syncage. - Sync state will now flip from RECONNECTING to ERROR after FAILED_SYNC_ERROR_THRESHOLD syncs
This commit is contained in:
17
src/sync.js
17
src/sync.js
@@ -39,8 +39,6 @@ const DEBUG = true;
|
|||||||
// to determine the max time we're willing to wait.
|
// to determine the max time we're willing to wait.
|
||||||
const BUFFER_PERIOD_MS = 80 * 1000;
|
const BUFFER_PERIOD_MS = 80 * 1000;
|
||||||
|
|
||||||
// Number of consecutive failed /sync requests
|
|
||||||
let failedSyncCount = 0;
|
|
||||||
// Number of consecutive failed syncs that will lead to a syncState of ERROR as opposed
|
// Number of consecutive failed syncs that will lead to a syncState of ERROR as opposed
|
||||||
// to RECONNECTING. This is needed to inform the client of server issues when the
|
// to RECONNECTING. This is needed to inform the client of server issues when the
|
||||||
// keepAlive is successful but the server /sync fails.
|
// keepAlive is successful but the server /sync fails.
|
||||||
@@ -96,6 +94,7 @@ function SyncApi(client, opts) {
|
|||||||
this._keepAliveTimer = null;
|
this._keepAliveTimer = null;
|
||||||
this._connectionReturnedDefer = null;
|
this._connectionReturnedDefer = null;
|
||||||
this._notifEvents = []; // accumulator of sync events in the current sync response
|
this._notifEvents = []; // accumulator of sync events in the current sync response
|
||||||
|
this._failedSyncCount = 0; // Number of consecutive failed /sync requests
|
||||||
|
|
||||||
if (client.getNotifTimelineSet()) {
|
if (client.getNotifTimelineSet()) {
|
||||||
reEmit(client, client.getNotifTimelineSet(),
|
reEmit(client, client.getNotifTimelineSet(),
|
||||||
@@ -582,6 +581,9 @@ SyncApi.prototype._sync = function(syncOptions) {
|
|||||||
// polling with the same token.
|
// polling with the same token.
|
||||||
client.store.setSyncToken(data.next_batch);
|
client.store.setSyncToken(data.next_batch);
|
||||||
|
|
||||||
|
// Reset after a successful sync
|
||||||
|
self._failedSyncCount = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
self._processSyncResponse(syncToken, data);
|
self._processSyncResponse(syncToken, data);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -616,10 +618,8 @@ SyncApi.prototype._sync = function(syncOptions) {
|
|||||||
// saved.
|
// saved.
|
||||||
client.store.save();
|
client.store.save();
|
||||||
|
|
||||||
|
// Begin next sync
|
||||||
self._sync(syncOptions);
|
self._sync(syncOptions);
|
||||||
|
|
||||||
// Reset after a successful sync
|
|
||||||
failedSyncCount = 0;
|
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
if (!self._running) {
|
if (!self._running) {
|
||||||
debuglog("Sync no longer running: exiting");
|
debuglog("Sync no longer running: exiting");
|
||||||
@@ -633,8 +633,8 @@ SyncApi.prototype._sync = function(syncOptions) {
|
|||||||
console.error("/sync error %s", err);
|
console.error("/sync error %s", err);
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
|
||||||
failedSyncCount++;
|
self._failedSyncCount++;
|
||||||
console.log('Number of consecutive failed sync requests:', failedSyncCount);
|
console.log('Number of consecutive failed sync requests:', self._failedSyncCount);
|
||||||
|
|
||||||
debuglog("Starting keep-alive");
|
debuglog("Starting keep-alive");
|
||||||
// Note that we do *not* mark the sync connection as
|
// Note that we do *not* mark the sync connection as
|
||||||
@@ -650,7 +650,8 @@ SyncApi.prototype._sync = function(syncOptions) {
|
|||||||
self._currentSyncRequest = null;
|
self._currentSyncRequest = null;
|
||||||
// Transition from RECONNECTING to ERROR after a given number of failed syncs
|
// Transition from RECONNECTING to ERROR after a given number of failed syncs
|
||||||
self._updateSyncState(
|
self._updateSyncState(
|
||||||
failedSyncCount > FAILED_SYNC_ERROR_THRESHOLD ? "ERROR" : "RECONNECTING",
|
self._failedSyncCount >= FAILED_SYNC_ERROR_THRESHOLD ?
|
||||||
|
"ERROR" : "RECONNECTING",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user