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

Fix sync breaking when an invalid filterId is in localStorage #228

Merged
merged 1 commit into from
Oct 9, 2016

Conversation

pik
Copy link
Contributor

@pik pik commented Oct 9, 2016

  • if getFilter fails for a filterId, null out the localStorage id and redirect to the createFilter path.

Currently it keeps retrying at keepAlive without invalidating: https://github.com/matrix-org/matrix-js-sdk/blob/master/lib/sync.js#L386 (Probably this should actually check whether it is an error that can be recovered through retry or not, rather than looping endlessly?)

  • add spec
  • fix unit/matrix-client.spec.js http response not matching synapse
    Here is what a response looks like (note that httpStatus was missing from the mock response in the beforeEach() setup of the spec):
{
  "errcode":"M_UNKNOWN",
  "name":"M_UNKNOWN",
  "message":"No row found",
  "data":{"errcode":"M_UNKNOWN","error":"No row found"},
  "httpStatus":404
}

@pik pik force-pushed the bug-invalid-filter branch 2 times, most recently from 6ff09df to 988e32a Compare October 9, 2016 18:25
@@ -2396,6 +2396,16 @@ MatrixClient.prototype.getOrCreateFilter = function(filterName, filter) {
// debuglog("Existing filter ID %s: %s; new filter: %s",
// filterId, JSON.stringify(oldDef), JSON.stringify(newDef));
return;
}, function(error) {
// {errcode: "M_UNKNOWN", name: "M_UNKNOWN", message: "No row found", data: Object, httpStatus: 404}
if (error.httpStatus === 404 && (error.errcode === "M_UNKNOWN" || error.errcode === "M_NOT_FOUND")) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated as discussed to use errcode instead of message.

@pik pik force-pushed the bug-invalid-filter branch from 988e32a to c8f5c4e Compare October 9, 2016 18:41
// {errcode: "M_UNKNOWN", name: "M_UNKNOWN", message: "No row found", data: Object, httpStatus: 404}
if (error.httpStatus === 404 && (error.errcode === "M_UNKNOWN" || error.errcode === "M_NOT_FOUND")) {
// Clear existing filterId if the localStorage value is out of sync with the server
self.store.setFilterIdByName(filterName, null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is necessary, since we're about to set it to something else below.

(if it were necessary, the 'out of sync' case would need updating too.)

Copy link
Contributor Author

@pik pik Oct 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah but the createFilter could fail and we might retry the whole thing, imho it makes sense to undefined it out if it's definitely been deleted.

// Clear existing filterId if the localStorage value is out of sync with the server
self.store.setFilterIdByName(filterName, null);
// Return a null value for existingId further down the promise chain
return null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably return undefined, for consistency with the 'out of sync' case and the 'unknown filter name' case.

(though I don't know why the out of sync case has an explicit return rather than just letting flow reach the end of the function.)

@pik pik force-pushed the bug-invalid-filter branch from c8f5c4e to 877a0ec Compare October 9, 2016 18:44
 * if getFilter fails for a filterId, null out the localStorage id and
   redirect to the createFilter path
 * add spec
 * fix unit/matrix-client.spec.js http response not matching synapse
@pik pik force-pushed the bug-invalid-filter branch from 877a0ec to 828c7ba Compare October 9, 2016 19:20
@richvdh richvdh merged commit 892ca56 into matrix-org:master Oct 9, 2016
@richvdh
Copy link
Member

richvdh commented Oct 9, 2016

Thanks!

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.

2 participants