Skip to content

Commit 2e7301f

Browse files
committed
backends/bluezdbus/manager: Release resources on bus restart
Call disconnect() on the old bus object if we have to reconnect to the D-Bus system bus. This ensures that file handles are released and we don't leak them.
1 parent 2e7192c commit 2e7301f

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0
1010
`Unreleased`_
1111
=============
1212

13+
Fixed
14+
-----
15+
- Fixed file handle leak in BlueZ backend when D-Bus connection is lost and re-established.
16+
1317
`1.1.1`_ (2025-09-07)
1418
=====================
1519

bleak/backends/bluezdbus/manager.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,11 @@ async def async_init(self) -> None:
350350
bus.disconnect()
351351
raise
352352

353+
if self._bus:
354+
# Even if we are disconnected, still need to call this to
355+
# release file handles.
356+
self._bus.disconnect()
357+
353358
# Everything is setup, so save the bus
354359
self._bus = bus
355360

0 commit comments

Comments
 (0)