From 7efd6385176169bcae5c5b54a1b6a24b4151f603 Mon Sep 17 00:00:00 2001 From: Arthur Crepin-Leblond Date: Thu, 25 Apr 2024 09:31:21 +0200 Subject: [PATCH] Fix _wait_removed completion on invalid object path The _wait_removed method registers the "InterfacesRemoved" callback on the adapter path of the device without checking which object was removed when called. This means that any removed interface while a connection is being established can cause the _wait_removed to complete and cancel the connection[1]. This commit simply checks that the callback is for the proper device object path. [1] https://github.com/hbldh/bleak/issues/1489 --- CHANGELOG.rst | 1 + bleak/backends/bluezdbus/manager.py | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index c0917c6e..7109415a 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -25,6 +25,7 @@ Fixed * Fixed BlueZ version in passive scanning error message. Fixes #1433. * Fixed mypy requiring ``Unpack[ExtraArgs]`` that were intended to be optional. Fixes #1487. * Fixed ``KeyError`` in BlueZ ``is_connected()`` and ``get_global_bluez_manager()`` when device is not present. Fixes #1507. +* Fixed BlueZ _wait_removed completion on invalid object path. `0.21.1`_ (2023-09-08) ====================== diff --git a/bleak/backends/bluezdbus/manager.py b/bleak/backends/bluezdbus/manager.py index 488dbb7b..6c835d21 100644 --- a/bleak/backends/bluezdbus/manager.py +++ b/bleak/backends/bluezdbus/manager.py @@ -812,8 +812,9 @@ async def _wait_removed(self, device_path: str) -> None: event = asyncio.Event() - def callback(_: str): - event.set() + def callback(o: str): + if o == device_path: + event.set() device_removed_callback_and_state = DeviceRemovedCallbackAndState( callback, self._properties[device_path][defs.DEVICE_INTERFACE]["Adapter"]