backends/corebluetooth: clear notify callbacks on disconnect#1997
Closed
miguel-neto-andrade wants to merge 1 commit into
Closed
backends/corebluetooth: clear notify callbacks on disconnect#1997miguel-neto-andrade wants to merge 1 commit into
miguel-neto-andrade wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1997 +/- ##
===========================================
- Coverage 52.45% 52.42% -0.03%
===========================================
Files 43 43
Lines 4097 4101 +4
Branches 504 504
===========================================
+ Hits 2149 2150 +1
- Misses 1817 1820 +3
Partials 131 131
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
CoreBluetooth stops notifications at the OS level when a peripheral
disconnects, but the PeripheralDelegate is reused when the same client
reconnects, so the stale entries in _characteristic_notify_callbacks
made a subsequent start_notify() raise ValueError("Characteristic
notifications already started").
Clear the notification bookkeeping in the disconnect callback so that
notifications can be started again after reconnecting.
Fixes #1969.
ee079d3 to
9fa1f71
Compare
Collaborator
|
I'm not a fan of the non-integration tests that are testing the implementation details. They don't check if it actually works with the OS Bluetooth stack and real hardware, so just give a false sense of things working correctly. |
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.
Fixes #1969.
On macOS, calling
start_notify()after disconnecting and reconnecting with the sameBleakClientraisesValueError("Characteristic notifications already started").CoreBluetooth stops notifications at the OS level on disconnect, but the
PeripheralDelegateis reused on reconnect (BleakClientCoreBluetooth.connect()only creates a new one whenself._delegate is None), so the stale entries in_characteristic_notify_callbacks/_characteristic_notification_discriminatorssurvive the disconnect and trip the guard instart_notifications(). This matches the root cause analysis in the issue comments.Changes:
PeripheralDelegate.clear_notify_callbacks()and call it from the client'sdisconnect_callback, alongside the existing future cleanup.tests/integration/test_issue_1969.py(connect →start_notify→ disconnect → reconnect with the same client →start_notify), following the existing bumble-basedtest_issue_*pattern. It is CoreBluetooth-only viaskipif, since BlueZ tracks notification state at the D-Bus level and is unaffected.poe lint,poe typecheckand the unit tests pass locally on macOS.Verified on real hardware (macOS, Apple Silicon, BlueNRG-based peripheral): on develop the second start_notify() after reconnecting with the same client instance raises ValueError("Characteristic notifications already started"); with this branch the same connect → notify → disconnect → reconnect → notify sequence succeeds.