From 6ad750347962d73a281a2cef4f88f95627aab32f Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Mon, 28 Oct 2024 11:29:23 +0100 Subject: [PATCH] Fix: Do not retry Snapcast connection if we want to exit --- music_assistant/server/providers/snapcast/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/music_assistant/server/providers/snapcast/__init__.py b/music_assistant/server/providers/snapcast/__init__.py index b0cf60a6f..0cc1b5238 100644 --- a/music_assistant/server/providers/snapcast/__init__.py +++ b/music_assistant/server/providers/snapcast/__init__.py @@ -254,6 +254,7 @@ class SnapCastProvider(PlayerProvider): _snapserver_runner: asyncio.Task | None _snapserver_started: asyncio.Event | None _ids_map: bidict # ma_id / snapclient_id + _stop_called: bool def _get_snapclient_id(self, player_id: str) -> str: search_dict = self._ids_map @@ -282,6 +283,7 @@ async def handle_async_init(self) -> None: # set snapcast logging logging.getLogger("snapcast").setLevel(self.logger.level) self._use_builtin_server = not self.config.get_value(CONF_USE_EXTERNAL_SERVER) + self._stop_called = False if self._use_builtin_server: self._snapcast_server_host = "127.0.0.1" self._snapcast_server_control_port = DEFAULT_SNAPSERVER_PORT @@ -334,6 +336,7 @@ async def loaded_in_mass(self) -> None: async def unload(self) -> None: """Handle close/cleanup of the provider.""" + self._stop_called = True for snap_client_id in self._snapserver.clients: player_id = self._get_ma_id(snap_client_id) await self.cmd_stop(player_id) @@ -729,6 +732,9 @@ async def _start_builtin_server(self) -> None: def _handle_disconnect(self, exc: Exception) -> None: """Handle disconnect callback from snapserver.""" + if self._stop_called: + # we're instructed to stop/exit, so no need to restart the connection + return self.logger.info( "Connection to SnapServer lost, reason: %s. Reloading provider in 5 seconds.", str(exc),