Skip to content

Commit

Permalink
Fix double-disable legacy advertising set
Browse files Browse the repository at this point in the history
When legacy advertising set is disabled passively(by set termination),
the legacy advertising set won't be released, and the next
stop_advertising() call will try to disable it again and cause an error.
  • Loading branch information
zxzxwu committed Feb 6, 2024
1 parent f4aeaa6 commit 9eccc58
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions bumble/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -2065,7 +2065,9 @@ async def stop_advertising(self) -> None:
"""Stop legacy advertising."""
# Disable advertising
if self.legacy_advertising_set:
await self.legacy_advertising_set.stop()
if self.legacy_advertising_set.enabled:
await self.legacy_advertising_set.stop()
await self.legacy_advertising_set.remove()
self.legacy_advertising_set = None
elif self.legacy_advertiser:
await self.legacy_advertiser.stop()
Expand Down Expand Up @@ -2207,9 +2209,6 @@ def is_advertising(self):
if self.legacy_advertiser:
return True

if self.legacy_advertising_set and self.legacy_advertising_set.enabled:
return True

return any(
advertising_set.enabled
for advertising_set in self.extended_advertising_sets.values()
Expand Down Expand Up @@ -3541,11 +3540,9 @@ def on_advertising_set_termination(
connection_handle,
number_of_completed_extended_advertising_events,
):
# Legacy advertising set is also one of extended advertising sets.
if not (
advertising_set := (
self.extended_advertising_sets.get(advertising_handle)
or self.legacy_advertising_set
)
advertising_set := self.extended_advertising_sets.get(advertising_handle)
):
logger.warning(f'advertising set {advertising_handle} not found')
return
Expand Down

0 comments on commit 9eccc58

Please sign in to comment.