From 615d535c0c59a0ca3916ed44f7160021d063f3fa Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Fri, 2 Jan 2026 11:30:48 +0100 Subject: [PATCH] Disconnect sendspin clients to allow clean shutdown (#2887) I was unable to do a clean shutdown in development when a Sendspin client was connected to the Sendspin server. This PR fixes it. STR - Start MA - Connect sendspin client (I was using sendspin-js) - Shut down MA using ctrl+C - Hangs With this PR: shuts down cleanly --- music_assistant/providers/sendspin/provider.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/music_assistant/providers/sendspin/provider.py b/music_assistant/providers/sendspin/provider.py index 9c5028bd..0cde94a6 100644 --- a/music_assistant/providers/sendspin/provider.py +++ b/music_assistant/providers/sendspin/provider.py @@ -103,12 +103,23 @@ class SendspinProvider(PlayerProvider): :param is_removed: True when the provider is removed from the configuration. """ + # Disconnect all clients before stopping the server + clients = list(self.server_api.clients) + disconnect_tasks = [] + for client in clients: + self.logger.debug("Disconnecting client %s", client.client_id) + disconnect_tasks.append(client.disconnect(retry_connection=False)) + if disconnect_tasks: + results = await asyncio.gather(*disconnect_tasks, return_exceptions=True) + for client, result in zip(clients, results, strict=True): + if isinstance(result, Exception): + self.logger.warning( + "Error disconnecting client %s: %s", client.client_id, result + ) + # Stop the Sendspin server await self.server_api.close() for cb in self.unregister_cbs: cb() self.unregister_cbs = [] - for player in self.players: - self.logger.debug("Unloading player %s", player.name) - await self.mass.players.unregister(player.player_id) -- 2.34.1