Skip to content

fix(realtime): properly dispose of stale MQTT clients before reconnect - #32

Merged
stuartp44 merged 2 commits into
mainfrom
stu/cleanup_threads
Sep 1, 2026
Merged

fix(realtime): properly dispose of stale MQTT clients before reconnect#32
stuartp44 merged 2 commits into
mainfrom
stu/cleanup_threads

Conversation

@stuartp44

Copy link
Copy Markdown
Owner

This pull request improves the management of MQTT client connections in the MiniBrewRealtimeManager to prevent resource leaks and ensure clean disconnects, especially during reconnects and error scenarios. It introduces a helper method for disposing of MQTT clients, updates the reconnect and disconnect logic to use this helper, and adds a test to verify the correct behavior.

MQTT client management improvements:

  • Added the _dispose_mqtt_client helper method to realtime.py to handle safe disconnection and cleanup of MQTT clients, preventing stale sockets and threads.
  • Updated _async_do_connect, _handle_disconnected, and async_stop methods to use _dispose_mqtt_client for consistent cleanup during reconnection attempts, disconnect events, and shutdown. [1] [2] [3] [4]

Testing enhancements:

  • Added a unit test test_realtime_manager_disconnects_stale_client_before_reconnect to ensure that any existing MQTT client is properly disconnected before a new connection is established.

@stuartp44 stuartp44 linked an issue Sep 1, 2026 that may be closed by this pull request
@stuartp44
stuartp44 merged commit 2cf2d85 into main Sep 1, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue after update to version 0.10

1 participant