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

2 commits

Author SHA1 Message Date
58be00cb38 docs: fix misleading comment on post-auth disconnect path
The comment said "treat as non-fatal" but the code calls fail() — which
is correct behavior since we can't write config without a connection.
Updated comment to accurately describe the fail-with-retry-prompt flow.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-21 23:03:43 +00:00
54fa973d34 fix: prevent re-entrant disconnect callbacks and handle all disconnect states
- Add isTerminating flag to guard succeed()/fail() against double invocation
  from racing didWriteValueFor + didDisconnectPeripheral callbacks
- Only call cancelPeripheralConnection when peripheral.state == .connected
  (avoids triggering spurious didDisconnectPeripheral on already-disconnected peripheral)
- Handle disconnect during device info read (post-auth) with specific error message
- Include state info in unexpected disconnect errors for easier debugging
- Early-return structure in disconnect handler for clearer control flow

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-21 23:01:30 +00:00