-
Notifications
You must be signed in to change notification settings - Fork 23
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
LDClient.isInitialized doesn't evaluate to true immediately after LDClient.init() finishes with a timeout #284
Comments
Hi @hikaritenchi, thank you for taking the time to gather those timestamps. I'm happy to help. Without more info, this may be expected behavior. Version 5.5.0 added some polling interval logic that may be at play here.
Theories:
|
Hi @tanderson-ld, I think I figured out the problem. I was using a Hilt-provided LDClient which had the wait set to 0, so trying to When I changed the Hilt LDClient to have a wait of 1, it returned I've spent a long time shortening this response from my previous long drafts, but I feel like the crux of the problem that I had was a disconnect between:
So while I agree that this is expected behavior, it is not explicitly explained in the documentation, which is what started this multi-day adventure for me. I would love to see a new section of the SDK reference docs for first run situations, or mention the distinction between the disconnects I referenced above, or just better organized in general so the information is not so easily glossed over, requiring extra interpretation. Additional documentation in the javadoc would be very welcome as well. Other wishlist items I had:
I'm happy to attempt to write some of this documentation if that would be helpful. |
You are certainly not the first to face this confusion around I recommend initializing the SDK in a class that extends the Android Application class as the LDClient instance will be globally useable within your application and there are likely components of your application that want to use feature flags that don't have UI/ViewModel components, such as a background service. |
Is this clarifying?
A follow up to this part: The need to use the timeout really depends on the customer use case and the app architecture. A well designed app will be reactive to feature flag changes and will not need to wait at the start to get feature flags. When the SDK gets the latest data, the app will fluidly handle the change. The reality is that can be very difficult to accomplish, even in a new codebase with that as a goal from the start of the project. Most customers have architectures that prefer to have the flags up front and then kept stable. For those customers, they typically make a tradeoff of getting feature flags in parallel to other startup tasks/requests and will wait at most a second or two. After that, they choose to proceed into the app with cached values or if there are really critical feature flags, they may block the user from getting into the app (very rare). |
Yes, I believe that is sufficient clarification for As for my comment, and in particular the part in parenthesis, that was more so me thinking out loud with regards to my specific implementation. I agree that these kinds of "I need the freshest data before the app can start!" requirements are very difficult to accomplish, and it's very helpful to have a timeout built in to the SDK rather than having to deal with potentially confusing Java Futures, especially since the deprecation reasoning is to prevent accidental blocking. I'm guessing the equivalent strategy might be to have a 0 timeout and attach a For our use case, we will probably try and force I'm comfortable with this issue being closed alongside the documentation updates being merged. |
Is this a support request?
Shouldn't be, but I think this is either a bug or some documentation should be changed.
Describe the bug
Immediately after
LDClient.init(a, conf, cont, 14)
returns, I expectLDClient.isInitialized
to return true, but it does not do so for a nontrivial amount of time, especially since I specified a nonzero timeout.To reproduce
Expected behavior
I expect
LDClient.isInitialized
to return true immediately afterLDClient.init()
is called with a nonzero timeout.Logs
2024-12-17 13:08:22.140 E start: 1734458902140
2024-12-17 13:08:22.142 E before: 1734458902141
2024-12-17 13:08:22.142 E client init: false
2024-12-17 13:08:22.441 E after: 1734458902440
2024-12-17 13:08:22.442 E client init: true
SDK version
5.5.0
Language version, developer tools
I think the only relevant information is Java 21 and Gradle 8.9. This was tested on the Android sample app.
OS/platform
Android 11
Additional context
If this isn't actually a bug, then I'd like to request some documentation updates because it's easy to confuse the fact that
isInitialized
shouldn't be true afterinit()
finishes. I can imagine a scenario where passing 0 for the wait would cause this situation to happen, but I've indicated that I am willing to wait forinit()
.The text was updated successfully, but these errors were encountered: