-
Notifications
You must be signed in to change notification settings - Fork 2.3k
fix(firestore, android): firestore instance cache key mismatch #9097
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
Open
russellwheatley
wants to merge
4
commits into
main
Choose a base branch
from
firestore-8981
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+78
−3
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c91c23f
fix(firestore, android): firestore instance cache key mismatch
russellwheatley 678dc30
test: android cache mismatch
russellwheatley 59edac4
fix: PR feedback, stop using weakreference, can be cleaned up by GC
russellwheatley cc8659c
test: e2e test should test the regression
russellwheatley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -124,6 +124,77 @@ describe('firestore()', function () { | |
| }); | ||
| }); | ||
|
|
||
| describe('issue 8981 - android firestore instance cache key mismatch', function () { | ||
| // A real, already-provisioned second database in the test project - see | ||
| // packages/firestore/e2e/SecondDatabase/*.e2e.js. | ||
| const SECOND_DATABASE_ID = 'second-rnfb'; | ||
|
|
||
| it('does not throw when switching databases on the same app and reapplying settings', async function () { | ||
| if (Platform.other) { | ||
| // Not supported on web lite sdk - no persistent native instance cache to break | ||
| return; | ||
| } | ||
|
|
||
| const { initializeApp, deleteApp } = modular; | ||
| const { getFirestore, doc, setDoc, getDoc } = firestoreModular; | ||
|
|
||
| // A dedicated, dynamically created app guarantees Firestore instances that have | ||
| // never been started before this test runs. | ||
| const appName = `firestoreIssue8981${FirebaseHelpers.id}`; | ||
| const app = await initializeApp(FirebaseHelpers.app.config(), appName); | ||
|
|
||
| try { | ||
| // Same app, two different database IDs. | ||
| // | ||
| // Regression test for https://github.com/invertase/react-native-firebase/issues/8981: | ||
| // on Android, `UniversalFirebaseFirestoreCommon.getFirestoreForApp()` read the | ||
| // instance cache keyed by `appName:databaseId` but wrote it back keyed by | ||
| // `appName` alone. Both databases therefore collided on a single cache slot | ||
| // that could never actually be hit on lookup (which always includes the | ||
| // `:databaseId` suffix) - switching from one database to another and back | ||
| // never protects either instance's settings from being re-derived. | ||
| const defaultDb = getFirestore(app); | ||
| const secondDb = getFirestore(app, SECOND_DATABASE_ID); | ||
|
|
||
| // Start the default database with an initial settings value. | ||
| await defaultDb.settings({ cacheSizeBytes: 1048576 }); | ||
| await setDoc(doc(defaultDb, `${COLLECTION}/issue8981/default`), { value: 1 }); | ||
|
|
||
| // Switch to the second database under the *same* app and start it too - this | ||
| // is the "different db ID hitting the same app" half of the bug: both native | ||
| // calls are keyed by the same broken, appName-only cache slot. | ||
| await secondDb.settings({ cacheSizeBytes: 2097152 }); | ||
| await setDoc(doc(secondDb, `${COLLECTION}/issue8981/second`), { value: 2 }); | ||
|
|
||
| // Switch back to the default database and reapply *different* settings to an | ||
| // already-started instance. Android's `FirebaseFirestore.setFirestoreSettings()` | ||
| // only throws when the newly-derived settings actually differ from what's | ||
| // already active (identical settings passed repeatedly are an explicit no-op | ||
| // in the native SDK) - so this value change is what deterministically triggers | ||
| // `IllegalStateException: FirebaseFirestore has already been started...` before | ||
| // the fix, once the cache-miss-on-every-call bug re-applies it natively. | ||
| await defaultDb.settings({ cacheSizeBytes: 5242880 }); | ||
| await setDoc(doc(defaultDb, `${COLLECTION}/issue8981/default`), { value: 3 }); | ||
|
|
||
| const [snap1, snap2] = await Promise.all([ | ||
| getDoc(doc(defaultDb, `${COLLECTION}/issue8981/default`)), | ||
| getDoc(doc(secondDb, `${COLLECTION}/issue8981/second`)), | ||
| ]); | ||
| snap1.data().value.should.equal(3); | ||
| snap2.data().value.should.equal(2); | ||
| } catch (e) { | ||
| // Fail explicitly with the regression context rather than letting the native | ||
| // `IllegalStateException` (surfaced here as a rejected promise) bubble up with a | ||
| // generic message - see https://github.com/invertase/react-native-firebase/issues/8981. | ||
| fail( | ||
| `Regression in issue 8981: switching database on the same app and reapplying settings should not throw, but got: ${e}`, | ||
| ); | ||
|
Comment on lines
+189
to
+191
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so here's the question - if you specifically do the pathological thing - now taking an already started firestore database and try to change it's settings in a way that should throw, does it throw? |
||
| } finally { | ||
| await deleteApp(app); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| describe('number type consistency', function () { | ||
| before(async function () { | ||
| // FIXME: | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.