fix: prevent re-entrant disconnect callbacks #4
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "schwifty/fix-disconnect-race"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Still getting "Unexpected disconnect" after PR #3 landed the SaveConfig fix.
Root Causes Found
Race condition in succeed()/fail(): When
succeed()is called fromdidDisconnectPeripheral, it callscancelPeripheralConnectionon an already-disconnected peripheral. On some iOS versions, this can trigger a SECONDdidDisconnectPeripheralcallback. Ifcleanup()has already reset the queue/index state, the second callback could hit the wrong path.Disconnect during device info read: After auth succeeds, there's a 3-second window reading the beacon's MAC address. During this,
stateis still.authenticating, so any disconnect falls through to the generic "Unexpected disconnect" handler.Fix
isTerminatingflag: Guardssucceed()andfail()against double invocation from racing CoreBluetooth callbacks. Checked at the top ofdidDisconnectPeripheralto skip expected cleanup disconnects.cancelPeripheralConnectionwhenperipheral.state == .connected(avoids triggering spurious callbacks on already-disconnected peripherals).Testing
Needs Xcode rebuild + test with physical beacon.