Skip to content

IllegalStateException: Multiple DataStores active for RN_KEYCHAIN.preferences_pb #784

@igork1984

Description

@igork1984

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:

  1. Use React Native 0.79.6 on an Android 14+ device.
  2. 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).
  3. The app crashes with IllegalStateException.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions