diff --git a/libraries/pushstore/impl/src/main/kotlin/io/element/android/libraries/pushstore/impl/DefaultUserPushStoreFactory.kt b/libraries/pushstore/impl/src/main/kotlin/io/element/android/libraries/pushstore/impl/DefaultUserPushStoreFactory.kt index a84fe2ea69..16100fd858 100644 --- a/libraries/pushstore/impl/src/main/kotlin/io/element/android/libraries/pushstore/impl/DefaultUserPushStoreFactory.kt +++ b/libraries/pushstore/impl/src/main/kotlin/io/element/android/libraries/pushstore/impl/DefaultUserPushStoreFactory.kt @@ -41,11 +41,13 @@ class DefaultUserPushStoreFactory @Inject constructor( // We can have only one class accessing a single data store, so keep a cache of them. private val cache = mutableMapOf() override fun create(userId: SessionId): UserPushStore { - return cache.getOrPut(userId) { - UserPushStoreDataStore( - context = context, - userId = userId - ) + return synchronized(cache) { + cache.getOrPut(userId) { + UserPushStoreDataStore( + context = context, + userId = userId + ) + } } }