-
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
Incorrect flag value returned after updating context #276
Comments
Hi @hoda0013, and thank you for reaching out and reporting this issue you're seeing. Also thank you for a really extensive set of details, that is always helpful. Your understanding that it should be caching the flag data in persistence is correct and that it should be able to serve those cached flags after you switch to the updatedContext. Do you see either of these logs from the code below when you switch to the updatedContext? Source
Additional information in case you debug a bit. The SDK uses the context's canonical key / fully qualified key as the unique identifier of the context for caching. You can call |
@tanderson-ld The only time I see the I started logging out the fully qualified key. What I see is that when I'm using the default, anonymous context After I update the context (but before I call ldClient.identify()) I ran through the test scenarios again and set the Launch Darkly log level to Debug. In the following log here's what actions I took to set the test up:
When the WorkManager job runs I do see the
About 5 seconds later I update the LD Context with the logged in user's information then request the flag value from LD. When I request the flags I see the following LD logs:
However, batch-close-dont-check-if-empty should be true not false. Is this helpful? Are there other logs you'd like to see that would help diagnose this more easily? Also, In the LDConfig there's the One other thing, when I call Thanks! |
You should see either of those two logs I mentioned when you call Do you expect to be initializing 3 clients? I see Can you verify the context that you are passing in the identify call is valid? I will spend some time in the next day or two to try to reproduce the issue on my side and let you know what I find. |
I'm seeing those two logs when I call LDClient.init() but am not seeing them when calling LDCLient.identify(), even when the flags are working as expected. In our LDConfig.Builder() we are setting a mobileKey() and two secondaryMobileKeys(). These correspond to production, development and staging environments. Is that why we'd be seeing the I will run another test to check if the context is valid and report back. Thanks! |
@tanderson-ld |
@tanderson-ld One more detail I should add. This is occurring on a Pax payment terminal Android device. We don't run this code on regular Android devices, only on Pax payment terminals so I have only observed this on a Pax device (but only because I have only run this code on a Pax device, it very well could be occurring on regular Android devices as well). |
@hoda0013, I apologize for not realizing this, but this issue is already fixed in our latest version and it was specifically fixed in 5.1.1. For some reason I was under the impression you were using the latest SDK version when I read through the issue originally. Are you able to update to the latest SDK version? Here is the 4.X to 5.X migration guide.. Since you are already using LDContext, I think it will be pretty straightforward for you. |
@tanderson-ld Thanks! |
Describe the bug
TL;DR
I start my app and am initializing LDClient with a default, anonymous context. I then update that context and set the context's key to the user's unique ID and then request a feature flag and I get the expected flag value returned. Then I then kill my app, put the device in airplane mode and start the app again, I go through the exact same process where I initialize the LDClient with a default, anonymous context, then update the context with the same user id and then request a feature flag, but this time the flag value is not correct and seems to be returning the values I'd expect if I was still using the the default, anonymous context.
A more in depth explanation of how the app is setup:
Whenever our app starts up, in Application.onCreate() we immediately call
LDClient.init(...)
with a default, anonymous LDContext. This is because we want to always initialize the LDClient as soon as the app's process is started and we don't yet know if the app has a logged in user (we'd have to make an async db call to determine this).Whenever we attempt to get a LD flag value, we check if the user is logged in. If they are and we haven't updated the LD context, we call LDClient.identify(newContext) and block until it returns. Then we use that context to get the flag value. This seems to generally work fine, but I'm running into an issue and either I'm misunderstanding how this should work or I've found a bug.
Here's the scenario:
My understanding at this point is that has cached that context and pulled down the correct flag values for that context and persisted them.
Now, we continue the scenario:
Initializing the LDClient in the application class:
Updating the context before requesting a flag. Using suspendCoroutine so that I can call .get() on the Future and not block the calling thread. Once the context has been updated, then we resume the coroutine.
To reproduce
Expected behavior
If I have accessed flags with my updated context, those flags should be cached and returned, even if the device is in airplane mode. If I do this exact same test and just don't put the device in airplane mode, everything works as expected.
Logs
If applicable, add any log output related to your problem.
SDK version
4.3.1
Language version, developer tools
Android Studio, Kotlin 1.8.10
OS/platform
Android
Additional context
Not sure if this matter, but, I'm seeing this happen when running an Android WorkManager job after the app has been killed. When the job triggers, first the application class starts, LDClient has init() called with the default, anonymous context, then the WorkManager job starts and updates the LDContext and requests a flag value.
The text was updated successfully, but these errors were encountered: