From a4e7a285d44cad759b18bfaf8c0c94b6cdd77cf7 Mon Sep 17 00:00:00 2001 From: James Mackay Date: Thu, 8 Oct 2026 09:27:50 +0100 Subject: [PATCH] =?UTF-8?q?fix(connection):=20let=20the=20library=20own=20?= =?UTF-8?q?keep=5Freconnecting's=20task=20=E2=80=94=20no=20double=20schedu?= =?UTF-8?q?ling=20on=20protocol=20start/stop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- custom_components/nvidia_shield/connection.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/custom_components/nvidia_shield/connection.py b/custom_components/nvidia_shield/connection.py index eefa81d..8290916 100644 --- a/custom_components/nvidia_shield/connection.py +++ b/custom_components/nvidia_shield/connection.py @@ -166,7 +166,6 @@ class ShieldConnectionManager: self._protocol = protocol self._protocol_settings = protocol_settings self._invalid_auth_callback = invalid_auth_callback - self._protocol_task: asyncio.Task | None = None self._protocol_loop: asyncio.AbstractEventLoop | None = None self._listeners: list[Callable[[], None]] = [] self._tasks: list[asyncio.Task] = [] @@ -251,10 +250,10 @@ class ShieldConnectionManager: client.add_is_available_updated_callback(self._on_is_available) client.add_current_app_updated_callback(self._on_current_app) client.add_volume_info_updated_callback(self._on_volume_info) - self._protocol_task = self._create_task( - client.keep_reconnecting(self._on_invalid_auth), - "shield_protocol_keep_reconnecting", - ) + # One owner per transport: the library's keep_reconnecting() creates + # and owns its reconnect task internally — we never wrap or duplicate + # it (the stop path closes the client, which tears the task down). + client.keep_reconnecting(self._on_invalid_auth) def _on_is_on(self, on) -> None: self._protocol_push(FIELD_IS_ON, bool(on)) @@ -420,9 +419,6 @@ class ShieldConnectionManager: tasks, self._tasks = self._tasks, [] for task in tasks: task.cancel() - if self._protocol_task is not None: - self._protocol_task.cancel() - self._protocol_task = None self._listeners.clear() if self._poller is not None: with contextlib.suppress(Exception):