Skip to content

Commit

Permalink
Fix: Do not retry Snapcast connection if we want to exit
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt committed Oct 28, 2024
1 parent 734dc5b commit 6ad7503
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions music_assistant/server/providers/snapcast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 6ad7503

Please sign in to comment.