fix: prevent re-entrant disconnect callbacks #4

Merged
schwifty merged 2 commits from schwifty/fix-disconnect-race into main 2026-03-21 23:37:08 +00:00
Showing only changes of commit 58be00cb38 - Show all commits

View file

@ -1013,12 +1013,13 @@ extension BeaconProvisioner: CBCentralManagerDelegate {
}
// Disconnect during device info read (post-auth, pre-write) beacon may have
// dropped the connection during the MAC address query. This is recoverable:
// we already authenticated, so treat as success without MAC.
// dropped the connection during the MAC address query. We authenticated but
// lost connection before writing config, so this is a failure but a known
// one with a clear retry path, not an unexplained "Unexpected disconnect".
if state == .authenticating && awaitingDeviceInfoForProvisioning && dxSmartAuthenticated {
DebugLog.shared.log("BLE: Disconnect during device info read (post-auth) — proceeding without MAC, treating as non-fatal")
DebugLog.shared.log("BLE: Disconnect during device info read (post-auth) — connection lost before config write, failing with retry prompt")
awaitingDeviceInfoForProvisioning = false
// Can't proceed without connection fail gracefully with specific message
// Connection lost can't write config without it, fail with specific message
fail("Disconnected after auth during device info read — please retry", code: .disconnected)
return
}