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

fixes races bug in react-native > 0.52 #938

Merged
merged 2 commits into from
Apr 9, 2018
Merged

fixes races bug in react-native > 0.52 #938

merged 2 commits into from
Apr 9, 2018

Conversation

taxidermic
Copy link
Contributor

In newer versions of react-native dispatch_async in setCurrentScreen causes mixed order. It's obvious if you make several calls of setCurrentScreen and logEvent in a small amount of time.

See: https://github.com/facebook/react-native/blob/0.54-stable/React/Base/RCTBridgeModule.h#L112

@Salakar Salakar added platform: ios plugin: analytics Google Analytics for Firebase labels Apr 5, 2018
@@ -5,6 +5,7 @@
#import <FirebaseAnalytics/FIRAnalyticsConfiguration.h>

@implementation RNFirebaseAnalytics
@synthesize methodQueue = _methodQueue;
Copy link
Contributor

Choose a reason for hiding this comment

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

@taxidermic I'm unsure why we need this queue, as the dispatch method is using dispatch_get_main_queue(), not the methodQueue you've defined?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The queue that will be used to call all exported methods. If omitted, this will call on a default background queue, which is avoids blocking the main thread.
....
If you don't want to specify the queue yourself, but you need to use it
inside your class (e.g. if you have internal methods that need to dispatch
onto that queue), you can just add `@synthesize methodQueue = _methodQueue;`
and the bridge will populate the methodQueue property for you automatically
when it initializes the module.

Docs I mentioned tells that if methodQueue is not synthesized, methods marked with RCT_EXPORT_METHOD will be called in global concurrent queue, which leads to messing. But! This passage lead me to wrong conclusions. My colleague(@vovkasm) made a big research about react-native/iOS interactions, and in fact it seems that react-native always makes that thing: https://github.com/facebook/react-native/blob/master/React/Base/RCTModuleData.mm#L209
So, it brings us to the point, where we don't need to use @synthesize methodQueue = _methodQueue;. But I would like to test it at first, so I'll do it and answer you tomorrow about the results.

Copy link
Contributor Author

@taxidermic taxidermic Apr 6, 2018

Choose a reason for hiding this comment

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

@chrisbianca Tested, yes, it works without @synthesize methodQueue = _methodQueue;!
Will you edit it by yourself, or should I send new pull_request? (I'm not sure how it works here ^^")

Btw, it fixes races only inside these structures separately. So, it's still possible, that

firebase.SetCurrentScreen(someProps)
firebase.LogEvent(anotherProps)

may mess up.

Though, several calls SetCurrentScreen will save their order

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 mean:

firebase.SetCurrentScreen(A)
firebase.LogEvent(E1)
firebase.SetCurrentScreen(B)
firebase.LogEvent(E2)

E1.screen == A и E2.screen == B, otherwords results will be accurate, though in Firebase Console you may see:

E1
screen_view(A)
screen_view(B)
E2

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @taxidermic , this is a good step in the right direction. We'll consider how best to synchronize across all the methods.

@chrisbianca chrisbianca merged commit f490221 into invertase:master Apr 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: ios plugin: analytics Google Analytics for Firebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants