music-assistant / hass-music-assistant

Turn your Home Assistant instance into a jukebox, hassle free streaming of your favorite media to Home Assistant media players.
Apache License 2.0
1.32k stars 49 forks source link

Music assistant does not reload HASS pluggin when HASS restarts #2760

Closed mjquinlan2000 closed 1 month ago

mjquinlan2000 commented 1 month ago

What version of Music Assistant has the issue?

2.1.4

What version of the Home Assistant Integration have you got installed?

2024.8.0

Have you tried everything in the Troubleshooting FAQ and reviewed the Open and Closed Issues and Discussions to resolve this yourself?

The problem

Every time I restart Home Assistant, the Music Assistant Plugin for Home Assistant does not reload properly and tells me that the plugin hasn't loaded yet. The logs indicate that it tries to connect to home assistance only once after 5 seconds and then stops.

I am running a bit of a unique setup. I have a 5 node Kubernetes cluster in my house and all of my home services run on that. The web-accessible services are exposed via Traefik ingress routes and I have DNS set up to point *.quitman.lan to the traefik instance. Both home assistant and music-assistant are accessible on my local network at home-assistant.quitman.lan and music-assistant.quitman.lan respectively.

Additionally, I have exposed them on a Layer2 IP address via a Kubernetes LoadBalancer service and metallb so they are accessible at 192.168.69.135 (home-assistant) and 192.168.69.151 (music-assistant).

Lastly, when communicating within the cluster they are available at the hostnames home-assistant and music-assistant.

I tried to use the intra-cluster hostnames when first setting it up and had some weird results because pod/service IP addresses are ephemeral and streaming back to my media devices couldn't resolve the correct hostnames. Using the local DNS also gave me some weird behavior. It appears that the static IPs assigned from the LoadBalancers work just fine when communicating between the 2 services.

At any rate, I think the problem might be that MASS is not retrying it's connection to home assistant. As previously stated, it says (in the logs) that it will try to connect again in 5 seconds, but then throws an exception 5 seconds later. The Kubernetes Home Assistant pod takes about a minute to come back online when it's restarted which obviously is far outside the 5 second timeout.

How to reproduce

I'm not sure if there's any way to easily reproduce this, other than deploying a minikube cluster with some manifests I could write up.

Music Providers

YouTube Music

Player Providers

Home Assistant

Full log output

music-assistant.log

Additional information

image

What version of Home Assistant Core are your running

2024.8.1

What type of installation are you running?

Home Assistant Core

On what type of hardware are you running?

Generic x86-64 (e.g. Intel NUC)

OzGav commented 1 month ago

This is actually already on the backlog https://github.com/orgs/music-assistant/projects/2/views/1?pane=issue&itemId=72559628

I will probably close this soon as the issue is being tracked internally and because your setup is not supported. Thanks for reporting though with excellent detail

marcelveldt commented 1 month ago

This is fixed in 2.2.0 beta 8 - if the fix is confirmed working, it will also be included in the patch release 2.1.5 for the stable version

OzGav commented 1 month ago

Yes this is confirmed. Takes about a minute but reconnects automatically

mjquinlan2000 commented 1 month ago

@marcelveldt @OzGav thank you!

mjquinlan2000 commented 1 month ago

Can confirm that it works on my system

2024-08-23 16:25:42.279 INFO (MainThread) [music_assistant.hass] Connection to HA lost. Connection will be automatically retried later.
2024-08-23 16:25:47.292 WARNING (MainThread) [music_assistant] Error loading provider(instance) Home Assistant: Cannot connect to host 192.168.69.135:80 ssl:default [Connect call failed ('192.168.69.135', 80)] (will be retried later)
2024-08-23 16:27:47.300 INFO (MainThread) [music_assistant] Loaded plugin provider Home Assistant
2024-08-23 16:27:47.324 INFO (MainThread) [music_assistant] Loaded player provider Home Assistant MediaPlayers