Skip to content

Commit

Permalink
Fix DBus connection leak
Browse files Browse the repository at this point in the history
Moved the try in order to include the call to the add_device_watcher function, since it is able to throw an error when the device does not exists in bluez anymore. This causes the just opened dbus connection to not be properly closed.
  • Loading branch information
koenvsteenb committed Dec 16, 2024
1 parent e01e264 commit 2615c5e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0

`Unreleased`_
=============
Fixed
-----
* Fix DBus connection leak when trying to connect to a forgotten ble device

`0.22.3`_ (2024-10-05)
======================
Expand Down
20 changes: 10 additions & 10 deletions bleak/backends/bluezdbus/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,18 @@ def on_value_changed(char_path: str, value: bytes) -> None:
if callback:
callback(bytearray(value))

watcher = manager.add_device_watcher(
self._device_path, on_connected_changed, on_value_changed
)
self._remove_device_watcher = lambda: manager.remove_device_watcher(
watcher
)
try:
watcher = manager.add_device_watcher(
self._device_path, on_connected_changed, on_value_changed
)
self._remove_device_watcher = lambda: manager.remove_device_watcher(
watcher
)

self._disconnect_monitor_event = local_disconnect_monitor_event = (
asyncio.Event()
)
self._disconnect_monitor_event = local_disconnect_monitor_event = (
asyncio.Event()
)

try:
try:
#
# The BlueZ backend does not disconnect devices when the
Expand Down

0 comments on commit 2615c5e

Please sign in to comment.