Skip to content
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

Merged
merged 2 commits into from Apr 5, 2017

Conversation

lukebarnard1
Copy link
Contributor

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

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;
Copy link
Member

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;
Copy link
Member

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",
Copy link
Member

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
@dbkr dbkr merged commit 6737d09 into develop Apr 5, 2017
@t3chguy t3chguy deleted the luke/fix-indicate-error-when-reconnecting branch May 10, 2022 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

when /versions succeeds but /sync fails, there is no disconnected indicator
2 participants