-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Description
In real-world multi-device scenarios (automatic reconnects, background operation, periodic retrieval of known devices), the current implementation can end up creating multiple logical wrappers for the same CBPeripheral.identifier. When this happens, delegate ownership may be overwritten, leading to “zombie” sessions where: writes may still succeed, but notifications / delegate callbacks are no longer delivered to the original wrapper.
This issue was surfaced by a real production-like use case involving multiple devices connecting and disconnecting without direct user interaction.
Current behavior
- APIs such as
retrieveConnectedPeripherals(and related connect paths) may create a new wrapper for aCBPeripheraleven if an existing wrapper for the same identifier is already active. - Creating a new wrapper can overwrite
cbPeripheral.delegate, breaking an existing logical session. - Repeated retrieval calls are therefore not idempotent and may disrupt active connections.
Desired behavior
- Within a single
BluetoothCentralinstance, there must be at most one live logical wrapper per CBPeripheral.identifier at any given time. - Retrieval-style APIs should be idempotent.
- Repeated calls must not create duplicate wrappers for the same peripheral.
- Active sessions must not be disrupted by retrieval or reconnect paths.
- Wrapper identity and delegate ownership should be guaranteed consistently across: scan-based discovery, retrieve APIs, explicit connect flows.
The goal is to address this at the central/identity level, rather than patching individual call sites.
A related PR helped surface this problem in a concrete scenario and is linked here for context: #8