Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

[Android] Client was already initialized error #40

Closed
haakandev opened this issue Feb 18, 2020 · 13 comments
Closed

[Android] Client was already initialized error #40

haakandev opened this issue Feb 18, 2020 · 13 comments

Comments

@haakandev
Copy link

Describe the bug
I believe there's an issue when the App Context is alive but Activity Context has been destroyed (difference on Android explained here). As the JS side is trying to initialize/configure the LD client along with the UI, this seems to cause a conflict. My guess is that the client is still around within the Application Context?
The font change in the reproduction steps below is intended as a short-cut to destroy the UI/Activity Context.

This is somewhat related to #10, but here an actual issue rather than a 'nice to have' I think.

To reproduce

  1. Download & set up the hello world project as described: https://github.com/launchdarkly/hello-react-native
  2. Run on Android (I've been using emulator)
  3. With the app running on the device/emulator, navigate to device Settings > Display > Font size
  4. Change the font size
  5. Return to the hello world app

Expected behavior
The app to be able to re-create the activity context.

SDK version
2.2.0

Language version, developer tools
React Native 0.61.2

OS/platform
Android 9

Screenshot
Screenshot_1581987723

@torchhound
Copy link
Contributor

Hi @haakandev thanks for reporting this. Are you seeing this error in your application or only in the hello-react-native application? Is this more of a dev/hot reload issue or is this an issue affecting production code?

@haakandev
Copy link
Author

Hi @torchhound - thanks for the reply.
First encountered it in my own application, but figured using the sample application was a simple case for reproduction.
Gave it a try in release mode, and didn't have an issue.
Running it in debug mode but with fast refresh disabled still saw the issue occur.

In my own project I've 'promoted' the client to module scope to keep it alive, which seems to dodge this issue while developing. But would be nice if this wasn't required.

@sam1463
Copy link
Contributor

sam1463 commented Mar 31, 2020

I am also running into this on android. It happens when calling client.configure on android more than once in a running application. Is this not permitted? My use case is that there are multiple backend environments which are accessible by the same UI, so for parts of the app for a user who is not logged in, we use the LaunchDarkly key for the production environment, but if the user logs in to a different backend environment, we call client.configure with the appropriate client config for that environment. That works fine on iOS but hits this error on android.

@torchhound
Copy link
Contributor

@sam1463 client.configure is not meant to be called multiple times. Multi-environment support is coming to React Native soon. This feature enables exactly the sort of workflow you are describing. As it stands right now I think what you are doing is undefined behavior.

@sam1463
Copy link
Contributor

sam1463 commented May 6, 2020

@torchhound ok thanks. How soon do you think it'll be ready? Just looking for an order of magnitude like next few days/weeks vs a few months vs a year or more

@torchhound
Copy link
Contributor

@sam1463 ballpark estimate of months but no promises. We are aware that many devs are interested in this feature.

@haakandev
Copy link
Author

Any updates/progress on this?

After upgrading to RN 0.62.2 (launchdarkly-react-native-client-sdk@3.1.2) I'm getting this issue again in dev mode. This despite the work-around in my previous comment. It makes development painful...

Slightly different error log:
Screenshot_1594815201

@davemarquess
Copy link

hi there - any updates on this? still seeing this error in dev mode on Android with RN 0.63.4
(launchdarkly-react-native-client-sdk@3.2.1)

@bwoskow-ld
Copy link
Member

We're actively working on some dependencies which need to be resolved before we bring the multi-environment feature to the React Native SDK. We expect to circle back to this early in the new year.

@davemarquess
Copy link

davemarquess commented Dec 17, 2020

Ok i see, thanks for the update @bwoskow-ld. And was curious:

the multi-environment feature to the React Native SDK.

^ does this mean the LD React Native SDK only currently works (without throwing above error) on iOS?

@bwoskow-ld
Copy link
Member

No, the React Native SDK works on both iOS and Android. See the repository readme for information about our supported versions.

@Ali-Ayyad
Copy link

Ali-Ayyad commented Mar 15, 2021

Any update on this issue ? Im running into the same error when i exit the app using the android back button. Even though im using LDClient.close() and .flush() and .unregisteringFlagListeners before the app exiting. If i kill the app and open it again this issue doesn't show up. This is happening on production not just debug mode.

@torchhound
Copy link
Contributor

The React Native SDK will no longer allow configure to be called if the SDK is already initialized. It does not error and will reject the promise if the SDK is already initialized.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants