New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Indicate syncState ERROR after many failed /syncs #410
Conversation
when a /sync leads to an error, increase a counter and use the counter to decide which state to be in when starting keepAlives. If the count is above a certain threshold (arbitrary 3 chosen here), switch from RECONNECTING to ERROR to show that the server is facing difficulties that aren't affeting is ability to return on /versions.
src/sync.js
Outdated
@@ -39,6 +39,13 @@ const DEBUG = true; | |||
// to determine the max time we're willing to wait. | |||
const BUFFER_PERIOD_MS = 80 * 1000; | |||
|
|||
// Number of consecutive failed /sync requests | |||
let failedSyncCount = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a member variable on SyncApi to match all the others (there could be multiple SyncApi objects).
src/sync.js
Outdated
@@ -610,6 +617,9 @@ SyncApi.prototype._sync = function(syncOptions) { | |||
client.store.save(); | |||
|
|||
self._sync(syncOptions); | |||
|
|||
// Reset after a successful sync | |||
failedSyncCount = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wants to be within the _sync function in the done()
(somewhere around client.store.setSyncToken(data.next_batch);
). This doesn't do what you think because _sync doesn't block, ie. this will set failedSyncCount
to 0 right after starting a sync request.
src/sync.js
Outdated
self._updateSyncState("RECONNECTING"); | ||
// Transition from RECONNECTING to ERROR after a given number of failed syncs | ||
self._updateSyncState( | ||
failedSyncCount > FAILED_SYNC_ERROR_THRESHOLD ? "ERROR" : "RECONNECTING", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor, but this probably wants to be >= rather than > so the ERROR state is triggered after FAILED_SYNC_ERROR_THRESHOLD failed syncs which is probably just a bit more intuitive than after n + 1 failed syncs which is what this does.
- 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
when a /sync leads to an error, increase a counter and use the counter to decide which state to be in when starting keepAlives. If the count is above a certain threshold (arbitrary 3 chosen here), switch from RECONNECTING to ERROR to show that the server is facing difficulties that aren't affeting is ability to return on /versions.
Attempts to fix element-hq/element-web#3336