fix: separate retry counter for device info disconnect #6

Closed
schwifty wants to merge 0 commits from schwifty/fix-device-info-retry-counter into main
Collaborator

Problem

The device info disconnect handler was sharing connectionRetryCount with the initial connection retry logic. If earlier connection attempts used retries, the device info handler had zero retries left and immediately failed with "Disconnected while reading device information (retries exhausted)".

This is the error John reported — the awaitingDeviceInfoForProvisioning guard from PR #4 was catching the disconnect correctly, but the shared counter meant it had no retries to use.

Fix

  • Added dedicated deviceInfoRetryCount (max 2) so device info retries are independent of connection retries
  • Reset in all the same places as connectionRetryCount
  • Better logging includes the device-info-specific counter

Test plan

  • Beacon disconnect during MAC read (~3s window) should reconnect and skip MAC
  • Multiple initial connection failures followed by successful connect + device info disconnect should still retry
  • Happy path provisioning unaffected
## Problem The device info disconnect handler was sharing `connectionRetryCount` with the initial connection retry logic. If earlier connection attempts used retries, the device info handler had zero retries left and immediately failed with "Disconnected while reading device information (retries exhausted)". This is the error John reported — the `awaitingDeviceInfoForProvisioning` guard from PR #4 was catching the disconnect correctly, but the shared counter meant it had no retries to use. ## Fix - Added dedicated `deviceInfoRetryCount` (max 2) so device info retries are independent of connection retries - Reset in all the same places as `connectionRetryCount` - Better logging includes the device-info-specific counter ## Test plan - [ ] Beacon disconnect during MAC read (~3s window) should reconnect and skip MAC - [ ] Multiple initial connection failures followed by successful connect + device info disconnect should still retry - [ ] Happy path provisioning unaffected
schwifty added 4 commits 2026-03-21 23:35:30 +00:00
- 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>
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>
The beacon sometimes drops BLE connection during the optional MAC address
query (0x30) after auth. Previously this failed with "Disconnected after
auth during device info read". Now we reconnect and skip the MAC read on
retry, going straight to config write. MAC is nice-to-have, not required.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The device info disconnect handler was sharing connectionRetryCount with
the initial connection retry logic. If earlier connection attempts burned
through retries, the device info handler had zero retries left and
immediately hit "retries exhausted" — causing the "Disconnected while
reading device information" error John reported.

Now uses a separate deviceInfoRetryCount (max 2) so device info retries
are independent of connection retries.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
koda closed this pull request 2026-03-21 23:38:22 +00:00
koda reopened this pull request 2026-03-21 23:39:25 +00:00
Collaborator

Changes already merged to main via direct merge (commit 720c560). Closing — code is live.

Changes already merged to main via direct merge (commit 720c560). Closing — code is live.
koda closed this pull request 2026-03-21 23:39:56 +00:00

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: payfrit/payfrit-beacon-ios#6
No description provided.