From 51605da2964df8049ba10ce499a0514f6055f74c Mon Sep 17 00:00:00 2001 From: Amr Yousef Date: Tue, 1 Oct 2024 17:41:40 +0100 Subject: [PATCH] Always Release storeLock --- .../store/store5/impl/RealMutableStore.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/impl/RealMutableStore.kt b/store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/impl/RealMutableStore.kt index f5dbb54f9..84fd02948 100644 --- a/store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/impl/RealMutableStore.kt +++ b/store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/impl/RealMutableStore.kt @@ -203,10 +203,13 @@ internal class RealMutableStore Output, ): Output { storeLock.lock() - val threadSafety = requireNotNull(keyToThreadSafety[key]) - val output = threadSafety.block() - storeLock.unlock() - return output + try { + val threadSafety = requireNotNull(keyToThreadSafety[key]) + val output = threadSafety.block() + return output + } finally { + storeLock.unlock() + } } private suspend fun conflictsMightExist(key: Key): Boolean {