Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deadlock when calling connect from scan callback on macOS #311

Open
TellowKrinkle opened this issue Jun 2, 2024 · 0 comments
Open

Deadlock when calling connect from scan callback on macOS #311

TellowKrinkle opened this issue Jun 2, 2024 · 0 comments

Comments

@TellowKrinkle
Copy link

If you attempt to call peripheral.connect from the callback of set_callback_on_scan_found or set_callback_on_scan_updated, self.peripheral.state will be forever stuck in CBPeripheralStateConnecting until the WAIT_UNTIL_FALSE_WITH_TIMEOUT(self, _task.pending, 5.0) times out.

This is because set_callback_on_scan_found callbacks are called from delegate_did_discover_peripheral which is called from a CBCentralManager delegate callback, which is run on the CBCentralManager's queue. I'd guess the CBCentralManager does updates to all of its data structures on that queue (this is generally how Apple APIs handle thread safety), so by blocking the queue (by sleeping in connect) you prevent the code that updates peripheral.state from running.

This probably applies to any other callbacks as well (e.g. the notify callback).

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

No branches or pull requests

1 participant