-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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 exception caused by a race condition in the database module on iOS #2734
Fix exception caused by a race condition in the database module on iOS #2734
Conversation
The exception raised is 'createRepo called for Repo that already exists.' in FRepoManager.m It looks like we have to call the firebase database reference from the same thread/queue otherwise we have a race condition leading to that exception.
we are having the same problem. Are there any way to merge it? |
@valentinjob since release dates are unpredictable for open-source (well, for closed source too, but with open source you at least have the source) I strongly recommend you integrate the patch-package tool, and for situations where there is a known fix for a problem you have, integrate the patch in your code-base. You'll get a nice notice when later releases include the fix, but you'll be working without problem in the meanwhile. I can't remember I time in the last year where I was not carrying around at least one patch via patch-package but they are always different as they are integrated upstream and released. |
Codecov Report
@@ Coverage Diff @@
## v5.x.x #2734 +/- ##
=======================================
Coverage 76.02% 76.02%
=======================================
Files 61 61
Lines 1576 1576
=======================================
Hits 1198 1198
Misses 378 378 |
Hey there - are either of you two using this in the wild? To add some confidence that we know it's working? I have the v5.x.x branch in a very clean state right now, with a reliable test setup locally to get around the current v5 CI failures, and could easily merge a couple more patches in |
@mikehardy I've been using the patch in the wild for about 5 weeks now. Seems to work fine. |
Thanks for the feedback @jeanregisser - I'll queue this for the next v5 release then |
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.
LGTM
cc @russellwheatley one to update on v6 |
@Ehesp I think v6 doesn't need updating as the equivalent reference has already been taken out of the async dispatch: https://github.com/invertase/react-native-firebase/blob/master/packages/database/ios/RNFBDatabase/RNFBDatabaseTransactionModule.m#L68 |
…module This is similar to the patch done for react-native-firebase v5 See invertase/react-native-firebase#2734
### Description Follow up PR to #3320 This PR fixes crashes on iOS related to the database module. I had already patched those for `react-native-firebase` v5 (see invertase/react-native-firebase#2734). Turns out a similar patch is still needed for v6. I will submit a PR upstream too for v6. Also fixed broken push registration on iOS. There was a new call needed with v6. I upgraded `react-native-firebase` to v6.7.1 since it changed push registration too, this way we're already on top again (but for how long? 😉). These issues are reproducible only when using a real device. ### Tested - App doesn't crash anymore on iOS in release mode. - Push registration works I could NOT test push being received successfully as `notification-service` currently has a similar issue as `blockchain-api` did a couple of days ago (fixed in #3583). ### Related issues - Fixes #3622 - Fixes #3623 ### Backwards compatibility Yes.
Summary
I came across a race condition while working on our app: https://github.com/celo-org/celo-monorepo/tree/master/packages/mobile
The exception raised is
createRepo called for Repo that already exists.
inFRepoManager.m
It happens when using a transaction and db listener at the same time after initializing firebase.
https://github.com/celo-org/celo-monorepo/blob/833c2d3d2341185dc141aec901c9b2828e776de6/packages/mobile/src/firebase/firebase.ts#L21
Exception stacktrace
It looks like we have to get the firebase database reference from the same
thread/queue otherwise we have a race condition leading to that exception.
Here are screenshots showing the race condition captured while debugging the app.
You can see the 2 different code paths calling
createRepo:
from 2 different threads racing to cause the exception.first the transaction
second the db listener
This might affect v6 but we haven't upgraded yet.
Checklist
Android
iOS
e2e
tests added or updated in packages/**/e2eTest Plan
Ran our app without this patch -> the exception is raised.
Ran our app with this patch -> no exception is raised and the app behaves correctly.
Release Plan
[IOS] [BUGFIX] [DATABASE] - Fix race condition causing exception 'createRepo called for Repo that already exists.' to be raised when using transaction and db listener at roughly the same time.