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.39k stars 51 forks source link

Homeassistant hard crashes on playback #899

Closed craggyh closed 1 year ago

craggyh commented 2 years ago

What version of Music Assistant has the issue?

2022.8.4

The problem

When I play any music Spotify/Tunein after a few seconds my homeassistant hard crashes and I get a 504 gateway Timeout error when trying to load the UI. A restart of the homeassistant container is the only way to recover.

How to reproduce

Play anything and wait a few seconds

Relevant log output

No response

Additional information

No response

What version of Home Assistant Core are your running

2022.8.7

What type of installation are you running?

Home Assistant OS

On what type of hardware are you running?

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

MarvinSchenkel commented 2 years ago

Could you please provide some additional logging info from your HA log file?

erkr commented 2 years ago

@craigueh Will be reopened, when we receive more information

craggyh commented 2 years ago

Sorry for the delay, there is nothing showing in the logs. As soon as I start playback the logs just stop along with the HASS UI:

2022-10-06 15:21:10.257 INFO (MainThread) [homeassistant.components.webhook] Received message for unregistered webhook df6d22f36e7dadea1f42b488200fe3f9ba243cd9d895e5dddfb11ff1de65c30a from [ip removed]

2022-10-06 15:21:10.525 INFO (MainThread) [music_assistant.players.stream] Start Streaming queue track: tunein://radio/s15065 (RTÉ 2fm) for queue Kitchen Speakers - crossfade: False

2022-10-06 15:21:10.794 WARNING (MainThread) [music_assistant.stream] Got stream request for already running stream: de8503f0f6dc41269e169837dfe98343, playback may be disturbed!

That's it, nothing else appears until I restart the HA container..

craggyh commented 2 years ago

After some more testing I've discovered that Music Assistant only crashed HA when trying to play anything on a Linkplay device. It doesn't matter whether the media is tunein or spotify, if the device is a Linkplay speaker it all crashes. I have 4 different Linkplay devices, each on different firmware and the result is the same. However, if I try play on a device other than Linkplay it seems to work fine.

I enabled debug logging on the music_assistant component but it doesn't produce anything more useful:

2022-10-06 20:54:04.545 INFO (MainThread) [homeassistant.components.webhook] Received message for unregistered webhook da59385b104295e7523f4351fd9dfe2730fc6b2fc9462ce8282be03dd6b3c3ea from [ip removed] 2022-10-06 20:54:06.134 DEBUG (MainThread) [music_assistant.event] queue_items_updated media_player.kitchen_speakers 2022-10-06 20:54:06.137 DEBUG (MainThread) [music_assistant.event] queue_updated media_player.kitchen_speakers 2022-10-06 20:54:06.427 DEBUG (MainThread) [music_assistant.event] queue_updated media_player.kitchen_speakers 2022-10-06 20:54:06.429 DEBUG (MainThread) [music_assistant.event] queue_updated media_player.kitchen_speakers 2022-10-06 20:54:06.431 DEBUG (MainThread) [music_assistant.event] player_updated media_player.kitchen_speakers 2022-10-06 20:54:06.454 DEBUG (MainThread) [music_assistant.players.stream] Starting Queue audio stream for Queue Kitchen Speakers (PCM format: s16le - sample rate: 44100) 2022-10-06 20:54:06.454 INFO (MainThread) [music_assistant.players.stream] Start Streaming queue track: tunein://radio/s15065 (RTÉ 2fm) for queue Kitchen Speakers - crossfade: False 2022-10-06 20:54:06.454 DEBUG (MainThread) [music_assistant.event] queue_updated media_player.kitchen_speakers 2022-10-06 20:54:06.465 DEBUG (MainThread) [music_assistant.helpers.audio] start media stream for: tunein://radio/s15065 2022-10-06 20:54:06.466 DEBUG (MainThread) [music_assistant.helpers.audio] writer started for tunein://radio/s15065 2022-10-06 20:54:06.568 DEBUG (MainThread) [music_assistant.stream] Got GET request to /a7276e4d31194785b621f3731530195e.flac from [ip removed] headers: 2022-10-06 20:54:06.569 DEBUG (MainThread) [music_assistant.players.stream] client connected: [ip removed] 2022-10-06 20:54:06.571 DEBUG (MainThread) [music_assistant.players.stream] 1 clients connected 2022-10-06 20:54:06.715 DEBUG (MainThread) [music_assistant.event] queue_updated media_player.kitchen_speakers 2022-10-06 20:54:06.830 DEBUG (MainThread) [music_assistant.event] queue_updated media_player.kitchen_speakers 2022-10-06 20:54:07.562 INFO (MainThread) [homeassistant.components.webhook] Received message for unregistered webhook e5ec7bed252ac47799c05e71f8143503010f707a6af693fd93e025adc5c5b0d3 from [ip removed] 2022-10-06 20:54:07.592 INFO (MainThread) [homeassistant.components.webhook] Received message for unregistered webhook 655150b58d30880c0a54a6eb0986a10bbd697d6459a7d14806da0530969e2fe2 from [ip removed] 2022-10-06 20:54:08.614 INFO (MainThread) [homeassistant.components.webhook] Received message for unregistered webhook da59385b104295e7523f4351fd9dfe2730fc6b2fc9462ce8282be03dd6b3c3ea from [ip removed] ---at this point the HA UI dies and the logs stop.

I've no idea how to troubleshoot this. I'd love to be able to use Music Assistant as it looks excellent but not having much luck.

erkr commented 2 years ago

@craigueh Can you confirm the linkplay source players (the ones without the mass_ prefix) work when used directly via the standard media browser? This to discriminate where the issue originates from

ekamagn commented 2 years ago

Hi I have the same hard crashes, not checked the logs, need to hard reset the whole system to be able to reach HA.

The HACS "Linkplay-based speakers and sound devices" works perfectly with the standard media browser and with Spotcast and spotify integration.

@craigueh Can you confirm the linkplay source players (the ones without the mass_ prefix) work when used directly via the standard media browser? This to discriminate where the issue originates from

craggyh commented 2 years ago

I tested and yes, the link play device plays test mp3s and wav files fine from the media browser but the mass_ device hard crashes the same way as MA.

erkr commented 2 years ago

Thanks for the feedback. I guess that indicates the problem is most likely in MA and not the players themselves

marcelveldt commented 2 years ago

linkplay is the only integration that has direct support for Music Assistant. Maybe there's some error in the code that picks up the request from MA within the linkplay custom component. I do not own any link play based speakers myself so kind of hard to test. @nagyrobi are you available to have a quick look what this might be ? Please let me know if you need support from me on MA side.

nagyrobi commented 2 years ago

I also noticed this behavior, thus I removed all direct MA support from Linkplay component because of the same concern. The current release of Linkplay is like any arbitrary media player from MA's perspective. Not using any special hooks anymore.

However, the symptom remained. I don't exclude this is a Linkplay-component issue though, might be some kind of race between the two, making the whole HA going down, which points far beyond my programming knowledge - so I gave up on investigating. This is too shaky for me, breaking HA this hard would have serious negative effects on us (it maganges the entire heating system of the house, we don't wanna freeze) so for the moment I uninstalled MA and not using it anymore.

Sorry guys. I'm out at this point.

ekamagn commented 2 years ago

By removing the HACS Linkplay and Spotcast installs, and restart, HA finds the Linkplay devices as DLNA media players, configure them. Now install MA as described solved my problem.... I hope. No crashes so far. And Spotify works great with Linkplay.

Now we will explore the MA more, seems great so far.

marcelveldt commented 2 years ago

Looks like the Linkplay integration is causing a deadlock or unsafe operation on the event loop. This issue is probably in the Linkplay code but triggered by Music Assistant as it tries to control the linkplay component directly. I do not have any Linkplay devices to test it myself but I'll take a look at the code if I can spot anything obvious.

For now I suggest to not use any Linkplay devices with MA (and remove it from the supported players section).

nagyrobi commented 2 years ago

Linkplay component definitely needs some love, from a proffessional programmer...

marcelveldt commented 2 years ago

Also great suggestion by @ekamagn to add the linkplay devices as DLNA players

craggyh commented 2 years ago

I tried the DLNA route but still got a hard crash after about 30s.

marcelveldt commented 2 years ago

I tried the DLNA route but still got a hard crash after about 30s.

If you remove the linkplay component that should not happen. At least not that I have heard of so far. What kind of hardware do you run HA ?

nagyrobi commented 1 year ago

https://github.com/nagyrobi/home-assistant-custom-components-linkplay/issues/102#issuecomment-1312525211

@marcelveldt you succeeded to test the hardware?

marcelveldt commented 1 year ago

I will look into integrating linkplay support into MA directly when the first beta of MA v2 has landed. For now I recommend using DLNA to connect to these speakers, that should work fine.

OzGav commented 1 year ago

https://github.com/music-assistant/home-assistant-addon

Please move to V2 to resolve this. Note that it is still in beta so other issues may arise. However I am closing this as no further investigation will be done as V1 is no longer supported.