fix: add timeout for characteristic rediscovery hang #16

Closed
schwifty wants to merge 0 commits from schwifty/fix-rediscovery-hang into main
Collaborator

Problem

App gets stuck at "Re-discovering characteristics..." and never recovers.

When FFE2 (command characteristic) goes missing mid-write, the code enters a rediscovery path that calls discoverCharacteristics() — but if CoreBluetooth never fires didDiscoverCharacteristicsFor back (common with flaky BLE), there's no timeout. The write timeout was already cancelled, and the 90s global timeout may have mostly elapsed.

Fix

  • Added a dedicated 5-second charRediscoveryTimer for the rediscovery path
  • If it fires, it either retries rediscovery (up to MAX_CHAR_REDISCOVERY) or fails with .timeout
  • Timer is cancelled on successful rediscovery callback and in cleanup()

No more hanging.

## Problem App gets stuck at "Re-discovering characteristics..." and never recovers. When FFE2 (command characteristic) goes missing mid-write, the code enters a rediscovery path that calls `discoverCharacteristics()` — but if CoreBluetooth never fires `didDiscoverCharacteristicsFor` back (common with flaky BLE), there's **no timeout**. The write timeout was already cancelled, and the 90s global timeout may have mostly elapsed. ## Fix - Added a dedicated 5-second `charRediscoveryTimer` for the rediscovery path - If it fires, it either retries rediscovery (up to MAX_CHAR_REDISCOVERY) or fails with `.timeout` - Timer is cancelled on successful rediscovery callback and in `cleanup()` No more hanging.
schwifty added 1 commit 2026-03-22 03:18:56 +00:00
When FFE2 goes missing during writes, the rediscovery path had no
timeout — if CoreBluetooth never called back didDiscoverCharacteristics,
the app would hang at "Re-discovering characteristics..." indefinitely.

Adds a 5-second timeout per rediscovery attempt. If it fires, it either
retries (up to MAX_CHAR_REDISCOVERY) or fails with .timeout instead of
hanging forever.
schwifty closed this pull request 2026-03-22 18:43:35 +00:00

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
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#16
No description provided.