backends/bluezdbus/manager: fix ordering of scanner stop
This moves the removal of callbacks before stopping scanning. This
prevents unwanted callbacks triggered by the stopping, for example,
many devices will remove the TxPower and RSSI properties when scanning
stops. Some devices are removed completely when scanning stops.
@@ -368,6 +368,14 @@ class BlueZManager:
assert_reply(reply)
async def stop() -> None:
+ # need to remove callbacks first, otherwise we get TxPower
+ # and RSSI properties removed during stop which causes
+ # incorrect advertisement data callbacks
+ self._advertisement_callbacks.remove(callback_and_state)
+ self._device_removed_callbacks.remove(
+ device_removed_callback_and_state
+ )
+
async with self._bus_lock:
reply = await self._bus.call(
Message(
@@ -392,11 +400,6 @@ class BlueZManager:
)
assert_reply(reply)
- self._advertisement_callbacks.remove(callback_and_state)
- self._device_removed_callbacks.remove(
- device_removed_callback_and_state
- )
-
return stop
except BaseException:
# if starting scanning failed, don't leak the callbacks
@@ -473,6 +476,14 @@ class BlueZManager:
self._bus.export(monitor_path, monitor)
async def stop():
+ # need to remove callbacks first, otherwise we get TxPower
+ # and RSSI properties removed during stop which causes
+ # incorrect advertisement data callbacks
+ self._advertisement_callbacks.remove(callback_and_state)
+ self._device_removed_callbacks.remove(
+ device_removed_callback_and_state
+ )
+
async with self._bus_lock:
self._bus.unexport(monitor_path, monitor)
@@ -488,11 +499,6 @@ class BlueZManager:
)
assert_reply(reply)
- self._advertisement_callbacks.remove(callback_and_state)
- self._device_removed_callbacks.remove(
- device_removed_callback_and_state
- )
-
return stop
except BaseException:
