From 48679f443643aa0f5c7078a5081ec79b21942b59 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 3 Sep 2025 16:37:08 -0500 Subject: [PATCH] Fix Bluetooth reconnection logic (#2948) --- .../main/java/com/geeksville/mesh/service/SafeBluetooth.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/geeksville/mesh/service/SafeBluetooth.kt b/app/src/main/java/com/geeksville/mesh/service/SafeBluetooth.kt index a582bc28c..05d65b956 100644 --- a/app/src/main/java/com/geeksville/mesh/service/SafeBluetooth.kt +++ b/app/src/main/java/com/geeksville/mesh/service/SafeBluetooth.kt @@ -557,8 +557,12 @@ class SafeBluetooth(private val context: Context, private val device: BluetoothD @RequiresPermission(Manifest.permission.BLUETOOTH_CONNECT) fun asyncConnect(autoConnect: Boolean = false, cb: (Result) -> Unit, lostConnectCb: () -> Unit) { logAssert(workQueue.isEmpty()) + + // If there's already connection work in progress, clear it before starting new connection + // This can happen during reconnection where previous connection work wasn't properly cleared if (currentWork != null) { - throw AssertionError("currentWork was not null: $currentWork") + warn("Found existing work during asyncConnect: $currentWork - clearing it") + synchronized(workQueue) { stopCurrentWork() } } lostConnectCallback = lostConnectCb