Skip to content

fix(corebluetooth): send descriptor discovery event even on error#456

Open
mikatammi wants to merge 1 commit intodeviceplug:devfrom
purefunsolutions:fix/macos-descriptor-discovery-hang
Open

fix(corebluetooth): send descriptor discovery event even on error#456
mikatammi wants to merge 1 commit intodeviceplug:devfrom
purefunsolutions:fix/macos-descriptor-discovery-hang

Conversation

@mikatammi
Copy link

On macOS, peripheral:didDiscoverDescriptorsForCharacteristic:error: only sent the
DiscoveredCharacteristicDescriptors event when error was nil. If CoreBluetooth reported
an error for any characteristic's descriptors (e.g. "The specified UUID is not allowed for
this operation"), the event was never emitted and discover_services() would hang
indefinitely waiting for all characteristics to be marked as discovered.

This is the macOS/CoreBluetooth equivalent of the Windows fix in #362 — descriptor discovery
errors should not block service discovery from completing.

The fix moves the event send and UUID extraction outside the if error.is_none() block, so
DiscoveredCharacteristicDescriptors always fires. On error, an empty descriptor map is
sent and a warning is logged, which unblocks the discovery future.

Tested with a Shelly Plug SG3 device whose FFF6 service characteristic triggers "The
specified UUID is not allowed for this operation" during descriptor discovery.

On macOS, `peripheral:didDiscoverDescriptorsForCharacteristic:error:`
only sent the `DiscoveredCharacteristicDescriptors` event when error
was nil. If CoreBluetooth reported an error for any characteristic's
descriptors (e.g. "The specified UUID is not allowed for this
operation"), the event was never emitted and `discover_services()`
would hang indefinitely.

This moves the event send outside the error check so it always fires
— with an empty descriptor map on error — allowing service discovery
to complete. A warning is now logged when descriptor discovery fails.

This matches the Windows behaviour where
`BLEDevice::get_characteristic_descriptors` uses `unwrap_or` to
return an empty list on error (PR deviceplug#362).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Mika Tammi <mikatammi@gmail.com>
@qwandor qwandor changed the base branch from master to dev March 18, 2026 21:26
@mikatammi
Copy link
Author

The clippy issues probably were already there before my PR? Should we fix them first?

@qdot
Copy link
Contributor

qdot commented Mar 19, 2026

Yup, I need to do a ton of clippy cleanup and hadn't been paying attention to actions, your PR is fine. I'll try to review soon.

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.

2 participants