Skip to content

fix(ios): fix thread-safety race in skipDescriptorDiscovery on reconnect#810

Merged
peitschie merged 2 commits into
mainfrom
ios-skip-descriptors-fix
Mar 5, 2026
Merged

fix(ios): fix thread-safety race in skipDescriptorDiscovery on reconnect#810
peitschie merged 2 commits into
mainfrom
ios-skip-descriptors-fix

Conversation

@peitschie

Copy link
Copy Markdown
Collaborator

On reconnect, CoreBluetooth uses cached GATT data and fires didDiscoverCharacteristicsFor near-instantly on the main queue, before the bridge thread's write to skipDescriptorDiscovery is visible — causing the stale false value to be read and the connection to time out.

Fix by dispatching setOnConnected synchronously to the main queue, matching the queue CoreBluetooth delegates run on. Apply the same fix to startScanning's scan filter properties for the same reason. Add comments on stateReceiver where the same issue exists but is too slow to manifest.

…ect (#809)

On reconnect, CoreBluetooth uses cached GATT data and fires
didDiscoverCharacteristicsFor near-instantly on the main queue, before
the bridge thread's write to skipDescriptorDiscovery is visible — causing
the stale false value to be read and the connection to time out.

Fix by dispatching setOnConnected synchronously to the main queue, matching
the queue CoreBluetooth delegates run on. Apply the same fix to
startScanning's scan filter properties for the same reason. Add comments
on stateReceiver where the same issue exists but is too slow to manifest.
Async barrier writes in the subscript setter and removeAll() created a
window where values were enqueued but not yet committed, causing
callbacks to be nil on fast reconnects.
@peitschie peitschie merged commit b6fb855 into main Mar 5, 2026
4 checks passed
@peitschie peitschie deleted the ios-skip-descriptors-fix branch March 5, 2026 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant