From fb0160b51919c9ae27a7781aa670de9e7976edb1 Mon Sep 17 00:00:00 2001 From: Narasimha-sc <166327228+Narasimha-sc@users.noreply.github.com> Date: Tue, 21 Apr 2026 20:48:42 +0000 Subject: [PATCH] android: fix QR scan retry tap outside race error (#6847) --- .../kotlin/chat/simplex/common/model/SimpleXAPI.kt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt index 7e0a7554ac..f62d4c262d 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt @@ -58,6 +58,7 @@ import kotlinx.serialization.descriptors.* import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder import kotlinx.serialization.json.* +import java.util.concurrent.atomic.AtomicBoolean import java.time.format.DateTimeFormatter import java.time.format.FormatStyle import java.util.Date @@ -723,14 +724,20 @@ object ChatController { val alert = if (r is API.Error) retryableNetworkErrorAlert(r.err) else null if ((inProgress == null || inProgress.value) && alert != null) { return suspendCancellableCoroutine { cont -> + val resumed = AtomicBoolean(false) + fun safeResume(result: Result) { + if (resumed.compareAndSet(false, true)) { + cont.resumeWith(result) + } + } showRetryAlert( alert, onCancel = { - cont.resumeWith(Result.success(null)) + safeResume(Result.success(null)) }, onRetry = { withLongRunningApi { - cont.resumeWith( + safeResume( runCatching { coroutineScope { sendCmdWithRetry(rhId, cmd, inProgress = inProgress, retryNum = retryNum + 1) @@ -742,7 +749,7 @@ object ChatController { ) cont.invokeOnCancellation { - cont.resumeWith(Result.success(null)) + safeResume(Result.success(null)) } } } else {