Repository navigation
Conversation
rabits
pushed a commit
to rabits/ha-ef-ble
that referenced
this pull request
Oct 3, 2026
Repeated BLE disconnects can leave retired Bleak clients holding D-Bus sockets. On my Linux Home Assistant host, HA held 233 connections when the system bus reached its 256-per-user limit and EcoFlow telemetry stopped. ## Changes - Retain each client until bounded cleanup finishes, including clients whose BLE link is already disconnected. - Keep cleanup outside cancelled auth/unload tasks, shield cleanup waiters, wait before reconnecting, and ignore callbacks from old clients. - On a BlueZ disconnect timeout or error, release the remaining D-Bus transport, device watcher, and disconnect monitor. Preserve the original caller in disconnect diagnostics. The fallback is limited to `BleakClientBlueZDBus`. It uses private Bleak 3.0.2 fields because there is no public force-close API; compatibility and lifecycle ordering deserve particular review. Other backends retain the public disconnect path. Scope is four files: connection cleanup, two regression-test suites, and Linux D-Bus / Python 3.13–3.14 CI setup. Preview packaging and version changes are on a separate branch. ## Validation - 170 tests passed on Python 3.13 and 3.14. The submitted head's fork CI passes Python tests, code style, HACS, and hassfest. - All 16 added regression cases pass; 13 fail on the unchanged upstream baseline used during implementation. All four real-D-Bus cases also fail on v1.1.2. - With real Bleak/D-Bus transports, 100 simulated remote drops leave no additional file descriptors; timeout, EOFError, and OSError paths release resources. - [Preview 1.1.3b2](https://github.com/kzkvv/ha-ef-ble/releases/tag/v1.1.3b2) has been tested on STREAM Ultra with a local Realtek USB adapter since September 17, with repeated checks over about two weeks. HA was subsequently upgraded from 2026.7.1 to 2026.9.4. - Live checks observed client sockets being released after natural drops and automatic reconnection. The latest October 2 check found two HA D-Bus connections, fresh telemetry, and the deployed preview unchanged. - Separate Bluetooth connectivity problems occurred earlier in the trial, and adapter startup timeouts remain. Telemetry has been substantially stable since September 26; the main later data gap coincided with a host reboot. This fix does not claim to resolve radio or adapter failures. See [fork PR #1](kzkvv#1) for the original validation record. Existing SHP3 test-fixture coroutine warnings were reproduced on the unchanged baseline and left out of scope.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
BLE disconnects left retired Bleak clients holding D-Bus sockets. On a Home Assistant host, 233 connections belonged to HA when the system bus exhausted its 256-per-user limit and STREAM Ultra telemetry stopped.
Retain each client until bounded cleanup finishes, even when
is_connectedis false. Keep cleanup outside cancellable auth/unload tasks, shield waiters, wait before reconnecting, and ignore old-client callbacks.If BlueZ disconnect times out or raises, release that client's remaining D-Bus socket, device watcher, and disconnect monitor. Bleak 3.0.2 has no public force-close API, so this fallback narrowly targets
BleakClientBlueZDBusprivate fields; other backends retain their existing public disconnect path. Capture caller diagnostics before spawning the cleanup task.Scope: four files only—connection lifecycle, two regression-test files, and Linux D-Bus / Python 3.13–3.14 CI setup. Fork packaging and versioning live on
codex/preview-ble-disconnect-cleanup.Validation:
Review: fixed lost caller context, added timeout/error cleanup after a separate reproduction, removed duplicate mock-loop coverage and fork-only PR content. Existing SHP3 test-fixture coroutine warnings reproduce unchanged upstream; left untouched.
Related open connection PRs rabits#450, rabits#487, rabits#507, and rabits#509 do not supply this transport cleanup. rabits#507 edits the same disconnect callback; coordinate/rebase if it lands first.
AI-assisted implementation and review. Prepared for upstream draft submission; hardware soak remains in progress.
Preview: https://github.com/kzkvv/ha-ef-ble/releases/tag/v1.1.3b2