From e7411d200088917141dbd02297011ed6c277e341 Mon Sep 17 00:00:00 2001 From: Florian Date: Sat, 23 May 2026 15:33:06 -0500 Subject: [PATCH] [BT] Reset BTProcessLock when immediateBTAction can't take the device semaphore (#2314) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit immediateBTAction() sets BTProcessLock=true and stops the scan before an outbound BLE action, and resets it on the success path and the "BLE busy" path — but the branch where semaphoreCreateOrUpdateDevice can't be taken left it true. Under scan contention that wedges the BLE scanner/connect subsystem until a restart (same BTProcessLock-mishandling family as the long-uptime NimBLE scanner hang). Reset it on that branch too. Co-authored-by: Claude Opus 4.7 (1M context) --- main/gatewayBT.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main/gatewayBT.cpp b/main/gatewayBT.cpp index 1f4bf0c..a1994ad 100644 --- a/main/gatewayBT.cpp +++ b/main/gatewayBT.cpp @@ -1692,6 +1692,10 @@ void immediateBTAction(void* pvParameters) { xSemaphoreGive(semaphoreCreateOrUpdateDevice); } else { THEENGS_LOG_ERROR(F("CreateOrUpdate Semaphore NOT taken" CR)); + // Release the process lock we took above; otherwise a transient + // semaphore-contention failure here leaves BTProcessLock=true and + // wedges the BLE scanner/connect subsystem until a restart. + BTProcessLock = false; } // If we stopped the scheduled connect for this action, do the scheduled now