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

Don't crash if write cannot be persisted #2938

Merged
merged 11 commits into from
Apr 21, 2020

Conversation

schmidt-sebastian
Copy link
Contributor

Addresses #2755

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Apr 18, 2020

Binary Size Report

Affected SDKs

  • @firebase/firestore

    Type Base (6cfb268) Head (56a3d07) Diff
    browser 248 kB 248 kB +268 B (+0.1%)
    esm2017 194 kB 194 kB +197 B (+0.1%)
    main 488 kB 488 kB +311 B (+0.1%)
    module 246 kB 246 kB +268 B (+0.1%)
  • @firebase/firestore/memory

    Type Base (6cfb268) Head (56a3d07) Diff
    browser 195 kB 195 kB +268 B (+0.1%)
    esm2017 152 kB 152 kB +197 B (+0.1%)
    main 377 kB 377 kB +311 B (+0.1%)
    module 194 kB 194 kB +268 B (+0.1%)
  • firebase

    Type Base (6cfb268) Head (56a3d07) Diff
    firebase-firestore.js 289 kB 290 kB +270 B (+0.1%)
    firebase-firestore.memory.js 238 kB 239 kB +270 B (+0.1%)
    firebase.js 823 kB 823 kB +270 B (+0.0%)

Test Logs

@nVitius
Copy link

nVitius commented Apr 18, 2020

Does this also address the issue if doing batched writes?

@schmidt-sebastian
Copy link
Contributor Author

Does this also address the issue if doing batched writes?

Yes.

userCallback.reject(
new FirestoreError(
Code.UNKNOWN,
'Query allocation failed with environment error: ' + e
Copy link
Contributor

@wilhuff wilhuff Apr 20, 2020

Choose a reason for hiding this comment

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

"Query allocation" seems like the wrong description of this error. Also, since this is catching everything, this isn't necessarily something to do with the environment. "Failed to enqueue a write in the local database"?

The catch here is also overbroad: this will catch internal assertion errors and the like as well. Taking an approach like the one I suggested in #2919 would make it possible to catch just errors related to IndexedDB.

Also, once we know the error is specifically about IndexedDB, I think the code can probably become DATA_LOSS. Or maybe UNAVAILABLE? DATA_LOSS is probably a bad choice because it is a permanent error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, "Query allocation" was the error message for my next PR.

I updated the PR with the changes in #2919 and only throw this error for IndexedDbTransactionErrors. I am a little uncertain whether we should just re-throw the error here or wrap it. For now, I decided to wrap it in a FirestoreError, as this makes it easier for our users to share error handling logic between the various backend errors and the new IndexedDB error.

result = await this.localStore.localWrite(batch);
} catch (e) {
// If we can't persist the mutation, we reject the user callback and don't
// send the mutation. The user can then retry the write. We currently do
Copy link
Contributor

Choose a reason for hiding this comment

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

This extra bit about not using enqueueRetryable isn't all that helpful. We're failing user writes because that's the developer experience we want users of the Firestore SDK to have. If we thought it was a better experience not to fail writes we'd make the changes required to make that happen.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed it.

@wilhuff wilhuff assigned schmidt-sebastian and unassigned wilhuff Apr 20, 2020
Copy link
Contributor

@wilhuff wilhuff left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -75,5 +75,61 @@ describeSpec(
.expectEvents(query, {});
}
);

specTest('Recovers when write cannot be persisted', [], () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do these tests need a no-ios and no-android tag or some new kind of tag to indicate that failure recovery is required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FYI: I pushed a commit to this PR to remove the durable-persistence tags as the new recovery tests also work with memory persistence. Most of my changes in my next PR were due to the formatting caused by this change.

@wilhuff wilhuff assigned schmidt-sebastian and unassigned wilhuff Apr 20, 2020
@schmidt-sebastian schmidt-sebastian merged commit a36b51b into master Apr 21, 2020
@firebase firebase locked and limited conversation to collaborators May 22, 2020
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/localwrites branch July 9, 2020 17:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants