-
Notifications
You must be signed in to change notification settings - Fork 29
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
BUG : Race condition when initializing SDK in EventRepository #492
Comments
Thanks for opening this issue! We'll get back to you shortly. If it is a bug, please make sure to add steps to reproduce the issue. |
Hey @ZacBeemer-JaneApp, Thanks for raising this issue. It seems you're using the self-hosted control plane URL and the metrics config is missing. I would request you to add the following config:
Or, try using the default control plane and try again:
Let us know if you are still facing any issues after performing the above steps. |
@1abhishekpandey Thank you for the suggestion! We'll look at implementing it and get back to you with whether it made a difference or not. Do you believe it's worth enhancing the logic to be more resilient / communicative regarding this issue in case other groups run into it as well? |
Sure, we will definitely work on improving that in the future. Currently, we are developing a new Android SDK built from scratch in Kotlin, which will address many improvements, including the issue you mentioned. |
Good evening, apologies for the delay. Adding that section to our source configuration does not appear to address this issue: Log output
Beyond addressing the race condition via a PR, are there any further suggestions for adjusting the Source Config that we could attempt? |
That is strange. I tried using the updated source config URL, and everything is working as expected in React Native Android. Can you please try uninstalling your app and then trying again? Also, let us know the version of the Android SDK you’re using. For example, here it’s version
Also instead of self-hosting URLs try using the RudderStack controlPlane and dataPlane URLs, just to check. You also mentioned something about an NPE. Could you please share your findings again, highlighting exactly where the NPE is triggered from and what is causing it on your end? We are unable to reproduce this scenario. I suspect that the NPE might be the root cause of the problem. |
@1abhishekpandey I believe I may have mishandled the change originally, as deleting and re-installing the app seems to have updated it to where it is now not showing the same, errant behaviour; Even over multiple "restarts" of the app. I hope that this means the source config is now fixed on our end 🤞 For what it's worth, the NPE stacktrace is as follows:
That points to the line of code where it's thrown as a result of the invalid source config. I think I'll close this issue for now. If the issue comes back, I'll re-open it or create a new one as appropriate. Thank you for all your help! |
Describe the bug
There appears to be a race condition causing silent failures when the
EventRepository
object is first initialized. This prevents the app from sending events to Rudderstack.We are working on a React Native project using the Rudderstack React Native SDK. We noticed that we were not receiving any messages from Android devices and, through a long and tedious process, uncovered that this Android SDK has an uncaught race condition which is silently causing the SDK Initialization process to hang and never complete.
The issue stems from how the RudderServerConfigManager class is using
ReentrantLock
.brokenThread()
logic beforenormalThread()
then the call tolock.unlock()
is never performed andnormalThread()
cannot proceed as it can never obtain the lock.More specifically, the scenario being played out in our testing is as follows:
EventRepository
is createdRudderServerConfigManager
constructor calls on RudderServerConfigManager.fetchConfig() which submits a task to be performed asynchronouslyfetchConfig()
method is exited regardless of whether or not the async logic is performedEventRepository
constructor then eventually calls EventRepository.initiateSDK()Server Config
existsRudderServerConfigManager.fetchConfig()
having been completed, which is not guaranteedRudderServerConfigManager.fetchConfig()
has not completed yet (ie. Slow download, device thread prioritization), theninitiateSDK()
will continue and enter its retry-loopinitiateSDK()
spawned a new Thread, it returns almost immediately andEventRepository
works its way down to EventRepository.initiateRudderReporterFromPrefetchedConfig()RudderServerConfigManager.fetchConfig()
having completedData Plane URL
Data Plane URL
is not available,ReportManager.enableStatsCollection()
throws an uncaught NullPointerExceptionReentrantLock
inRudderServerConfigManager
is not using the following suggested structure, the Thread that previously claimed the lock will never release it and all other Threads waiting for it will be stuck.flush()
will throw an error (if log output is explicitly configured), but otherwise not kill the appTo Reproduce
Steps to reproduce the behaviour:
Expected Behavior
The event should be fired off and no errors should be observed
Screenshots
Version of the Android SDK
Version of the Rudderstack Android SDK
Mobile device mode integration
SDK initialisation snippet
Check for Correct Usage of writeKey and dataPlaneUrl
Confirm that the correct
writeKey
anddataPlaneUrl
are utilized during SDK initialization.dataPlaneUrl
from being correctly initializedThe text was updated successfully, but these errors were encountered: