LMS-Community / slimserver

Server for Squeezebox and compatible players. This server is also called Lyrion Music Server.
https://lyrion.org
Other
1.11k stars 281 forks source link

LMS handling multi-IP DNS responses for playout (Home Assistant, mixed IPv4/IPv6 environments) #340

Open Moonbase59 opened 4 years ago

Moonbase59 commented 4 years ago

This is a follow-up to https://github.com/ralph-irving/squeezelite/issues/94.

The situation: You have a dual-stack (IPv4/IPv6) environment, use a IPv6-aware DynDNS service like AVM’s MyFritz for use with a Fritz!Box, and wish to play pre-recorded or TTS-generated alert messages through LMS media players, which in turn are hosted on the Home Assistant web server, under www/local in your config folder (or under /api/tts_proxy/… for TTS messages).

Our findings:

  1. Home Assistant is single-stack only. So, depending upon your configuration, it’ll either serve via IPv4 or via IPv6 but not both.
  2. The MyFritz DynDNS service will always do port forwarding and sharing for both IPv4 and IPv6 (if you’re in a dual-stack environment and your Internet provider supports it). This results in a DNS response containing both an IPv4 and an IPv6 address for your host.
  3. Now since HA is single-stack, only one of these host IP addresses will actually function ("No route to host" or "Cannot access host" being returned when trying to access the other).
  4. Many pieces of software (like wget, most browsers, VLC, KODI and others) will handle this gracefully by trying the next IP address given in the DNS response, until the list is exhausted. The first accessible IP address will be used to play the audio file.
  5. Note: Messages generated through TTS (Text-To-Speech) are usually mono and have very low bitrates and sampling rates your player might not support. In these cases, resampling might be necessary (i.e., -R hLE on the SqueezeLite command line, or via LMS’ custom-convert.conf).

The issue: LMS seems to have some issues here. See https://github.com/ralph-irving/squeezelite/issues/94#issuecomment-630134467 and https://github.com/ralph-irving/squeezelite/issues/94#issuecomment-630185189 for actual server logs.

Depending on the situation, it will either look like "playing" in the UI but no sound is heard, it might just show the URI, count up seconds and never start to play, or it’ll play correctly.

My proposal: Investigate this matter further, since parts of the code already seem to do things correctly. Also, if using a player that has "direct streaming" set and "CanHTTPS=1" (like SqueezeLite), it will usually work.

I’d suggest LMS behaving like others, i.e. trying all IP addresses presented in the DNS response in sequence, skipping to the next if an error occurs, and repeating until the list is exhausted, and only THEN show an error.

I reckon solving this shall make many Home Assistant + Logitech Media Server users very very happy—I’ve found so many postings on the internet regarding "Alerts/TTS doesn’t work with LMS" …

mherger commented 4 years ago

Isn't this just yet another dupe of #350?...

Moonbase59 commented 4 years ago

No, seems this has to do with SSL handshaking if one of the server IPs in a DNS response is unreachable.

Noting that we possibly fight with more than one problem, I have in the meantime made the server IPv4 only so this problem can't occur for now (DNS only offering one IPv4 now) and we can fix the other issue first. I'll then come back and test this again.

jsandquist commented 3 years ago

Home Assistant is now dual-stack in version 0.114 - see Other Noteworthy Changes in https://www.home-assistant.io/blog/2020/08/12/release-114/

(I just happened to read this issue yesterday and soon after 0.114 was released)