launchdarkly / android-client-sdk

LaunchDarkly Client-side SDK for Android
Other
44 stars 23 forks source link

ConnectionInformation doesn't get updated after identifying to a different context #226

Closed anawu2006 closed 1 week ago

anawu2006 commented 11 months ago

Is this a support request? No

Describe the bug In SDK 3.6.0, LDClient.get().connectionInformation will get updated with a new lastSuccessfulConnection value after identifying to a different user, but not in 5.0.0.

To reproduce

  1. init LDClient with ldContext1 and register a LDStatusListener
    LDClient.init(context, config, ldContext1, 3)
    LDClient.get().registerStatusListener(statusListener)
  2. switch to ldContext2:
    LDClient.get().identify(ldContext2)
  3. LDClient.get().connectionInformation doesn't get updated and LDStatusListener.onConnectionModeChanged doesn't get triggered.

Expected behavior LDClient.get().connectionInformation should be updated with a new lastSuccessfulConnection value and LDStatusListener.onConnectionModeChanged` should be triggered.

Logs None.

SDK version 5.0.0

Language version, developer tools Android Kotlin, API 34

OS/platform Android 13

Additional context I have checked the source code of ConnectivityManager.setStatusand noticed that LastSuccessfulConnection value won't be updated if the ConnectionMode doesn't change. I think the connection information should be updated in this case given the LDContext changed. But feel free to close this out if you don't think so.

tanderson-ld commented 11 months ago

Hi @anawu2006 , thank you for reporting this. We believe this bug has been in the code base since 4.x and has been overlooked. We have filed this internally as 211876.

Could you tell us a bit about how you are using the listener in your code base and the impact of this bug on your application? This will help us prioritize it against other issues. Thank you for taking the time to report!

anawu2006 commented 11 months ago

@tanderson-ld you are correct, this bug exists in 4.x as well.

In our app, having a new successful connection to LD server is one of the conditions when switching users/contexts. So after identifying, we wait until LDStatusListener.onConnectionModeChanged gets triggered with a new connectionInformation.lastSuccessfulConnection value.

With this issue, we are not able to switch users/contexts successfully. Any other suggested solutions to identify a new successful connection to server after identifying? Thanks.

tanderson-ld commented 11 months ago

Sorry for the delay @anawu2006 . Could you try setOffline(), identify, then setOnline()? I think that is enough to get the connection manager to change states.

anawu2006 commented 11 months ago

@tanderson-ld no worries and that is exactly what I had put up to bypass this issue. Thanks.

tanderson-ld commented 1 week ago

@anawu2006 , this issue should now be fixed in version 5.3.1 which was just released. Please be aware that the SDK may send multiple updates in quick succession with just the last connection timestamp updated.