-
-
Notifications
You must be signed in to change notification settings - Fork 532
Description
Description:
After upgrading to react-native-keychain v10.0.0, I am encountering a consistent crash on Android 14, 15, and 16. This is the IllegalStateException caused by Jetpack DataStore's strict singleton requirement.
Environment:
React Native Keychain Version: 10.0.0
React Native Version: 0.79.6 (Old Architecture)
Kotlin Version: 2.1.20
Android Versions Affected: API 34 (Android 14), API 35 (Android 15), and Android 16.
Stack Trace / Error Message:
java.lang.IllegalStateException: There are multiple DataStores active for the same file: /data/user/0/***/files/datastore/RN_KEYCHAIN.preferences_pb.
You should either maintain your DataStore as a singleton or confirm that there is no two DataStore's active...
JS Call Stack:
The crash is triggered by overlapping async calls. Even on the Old Architecture, calling the keychain in rapid succession causes the native side to fail:
const credentials = await Keychain.getGenericPassword({ service });
Context:
Despite not using the New Architecture, the combination of RN 0.79.6 and Kotlin 2.1.20 seems to trigger the DataStore initialization too quickly when multiple getGenericPassword calls are fired in parallel. The library does not appear to have a native-level mutex or singleton guard to prevent multiple DataStore instances from being created for the same file path if the previous request hasn't fully closed or settled.
Steps to Reproduce:
- Use React Native 0.79.6 on an Android 14+ device.
- Fire two or more Keychain.getGenericPassword calls at the same time (e.g., in a Promise.all or within a shared authentication logic used by multiple components on mount).
- The app crashes with IllegalStateException.