fix(ios): Improve reconnection stability (#803)#811
Merged
Conversation
…803) On rapid reconnect, setTimeout() would overwrite the timeoutMap entry without cancelling the old DispatchWorkItem. The old work item remained scheduled and could fire during the new operation, rejecting the wrong callback. Now explicitly cancel any existing work item for the same key before creating a replacement.
Plugin.connect() sets up two independent callbacks with timeouts: one at the Device level (GATT discovery) and one at the DeviceManager level (physical BLE connection). Both could reject the same CAPPluginCall if the DeviceManager timeout fired first, leaving the Device timeout as a zombie. Now when DeviceManager connect fails, the Device-level connect timeout is explicitly cancelled before rejecting the call.
…ror (#803) Previously, didDiscoverServices errors were logged but silently dropped, leaving the connect callback to time out after 10s with a generic "Connection timeout" message. Now the callback is rejected immediately with the actual error from CoreBluetooth.
…can + connect (#803) DeviceManager previously created its own Device objects in discoveredDevices during scanning. These competed with Plugin.deviceMap's Device objects for peripheral.delegate ownership, causing service discovery callbacks to fire on the wrong Device (one with no connect callback stored), leading to silent connection timeouts on reconnect. Root cause: Two separate Device objects wrapping the same CBPeripheral both called peripheral.delegate = self. Whichever touched it last won. Fix: DeviceManager now stores raw CBPeripheral references instead of Device objects. Device creation is solely owned by Plugin.deviceMap via getOrCreateDevice(). This guarantees exactly one Device per peripheral and eliminates the delegate ownership race entirely. Closes #803
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.