Repository: badaix/snapcast

Issue #518: Cannot bind to both IPv4 and IPv6 address
Created: 2019-12-26T20:18:42Z
As far as I understand the comments in /etc/snapserver.conf it should be possible to specify both, an IPv4 and an IPv6 address like this:
$ cat /etc/snapserver.conf | grep -B9 bind_to_address
[http]
# enable HTTP Json RPC (HTTP POST and websockets)
#enabled = true

# address to listen on, can be specified multiple times
# use "0.0.0.0" to bind to any IPv4 address or :: to bind to any IPv6 address
# or "127.0.0.1" or "::1" to bind to localhost IPv4 or IPv6, respectively
# use the address of a specific network interface to just listen to and accept
# connections from that interface
bind_to_address = ::
bind_to_address = 0.0.0.0
--
[tcp]
# enable TCP Json RPC
#enabled = true

# address to listen on, can be specified multiple times
# use "0.0.0.0" to bind to any IPv4 address or :: to bind to any IPv6 address
# or "127.0.0.1" or "::1" to bind to localhost IPv4 or IPv6, respectively
# use the address of a specific network interface to just listen to and accept
# connections from that interface
bind_to_address = ::
bind_to_address = 0.0.0.0
--
# Stream settings #############################################################
#
[stream]
# address to listen on, can be specified multiple times
# use "0.0.0.0" to bind to any IPv4 address or :: to bind to any IPv6 address
# or "127.0.0.1" or "::1" to bind to localhost IPv4 or IPv6, respectively
# use the address of a specific network interface to just listen to and accept
# connections from that interface
bind_to_address = ::
bind_to_address = 0.0.0.0

But on the other hand I get this:
$ sudo netstat -tulpen | grep snap
tcp6       0      0 :::1704                 :::*                    LISTEN      110        17706      1115/snapserver     
tcp6       0      0 :::1705                 :::*                    LISTEN      110        17696      1115/snapserver     
tcp6       0      0 :::1780                 :::*                    LISTEN      110        17698      1115/snapserver  

Interchanging the order of the IPv4 and IPv6 lines I get:
$ sudo netstat -tulpen | grep snap
tcp        0      0 0.0.0.0:1704            0.0.0.0:*               LISTEN      110        19029      1255/snapserver     
tcp        0      0 0.0.0.0:1705            0.0.0.0:*               LISTEN      110        19019      1255/snapserver     
tcp        0      0 0.0.0.0:1780            0.0.0.0:*               LISTEN      110        19021      1255/snapserver

So it seems bind_to_address is only interpreted once. Is this expected?

Duplicate issue #715: "Failed to connect to host" when snapclient is running in same device than snapserver
Created: 2020-11-04T00:00:47Z
Bug description
Only when :

just after powering up the machine
and
the machine have both snapclient and snapserver installed

, sometimes the snapclient fails to connect to the snapserver, and keeps trying (and failing) forever, unless i restart the service.
Logs
given the following 2 logs from journalctl, where the first is when the snapclient fails, and the second is after it restarted
1º. when it fails (the bug):
nov 03 19:57:30 raspberrypi snapclient[454]: (Browser) CACHE_EXHAUSTED
nov 03 19:57:30 raspberrypi snapclient[454]: (Browser) ALL_FOR_NOW
nov 03 19:57:31 raspberrypi snapclient[454]: (Browser) NEW: service 'Snapcast' of type '_snapcast._tcp' in domain 'local'
nov 03 19:57:31 raspberrypi snapclient[454]: (Browser) CACHE_EXHAUSTED
nov 03 19:57:32 raspberrypi snapclient[454]: (Browser) NEW: service 'Snapcast' of type '_snapcast._tcp' in domain 'local'
nov 03 19:57:32 raspberrypi snapclient[454]: (Browser) CACHE_EXHAUSTED
nov 03 19:57:32 raspberrypi snapclient[454]: Service 'Snapcast' of type '_snapcast._tcp' in domain 'local':
nov 03 19:57:32 raspberrypi snapclient[454]:         raspberrypi.local:1704 (fe80::7382:f90f:ad93:46c7)
nov 03 19:57:32 raspberrypi snapclient[454]: Found server fe80::7382:f90f:ad93:46c7%4:1704
nov 03 19:57:32 raspberrypi snapclient[454]: Resolving host IP for: fe80::7382:f90f:ad93:46c7%4
nov 03 19:57:32 raspberrypi snapclient[454]: Connecting
nov 03 19:57:32 raspberrypi snapclient[454]: Failed to connect to host 'fe80::7382:f90f:ad93:46c7%4', error: Connection refused
nov 03 19:57:32 raspberrypi snapclient[454]: Error: Connection refused
nov 03 19:57:32 raspberrypi snapclient[454]: Error in socket shutdown: Transport endpoint is not connected

nov 03 19:57:33 raspberrypi snapclient[454]: Resolving host IP for: fe80::7382:f90f:ad93:46c7%4
nov 03 19:57:33 raspberrypi snapclient[454]: Connecting
nov 03 19:57:33 raspberrypi snapclient[454]: Failed to connect to host 'fe80::7382:f90f:ad93:46c7%4', error: Connection refused
nov 03 19:57:33 raspberrypi snapclient[454]: Error: Connection refused
nov 03 19:57:33 raspberrypi snapclient[454]: Error in socket shutdown: Transport endpoint is not connected
...
the last 5 lines keeps repeating
....

2º. when it works fine (in this example, after restarting the service/process):
nov 03 19:58:40 raspberrypi systemd[1]: Started Snapcast client.
nov 03 19:58:40 raspberrypi snapclient[918]: (Browser) NEW: service 'Snapcast' of type '_snapcast._tcp' in domain 'local'
nov 03 19:58:40 raspberrypi snapclient[918]: (Browser) NEW: service 'Snapcast' of type '_snapcast._tcp' in domain 'local'
nov 03 19:58:40 raspberrypi snapclient[918]: (Browser) CACHE_EXHAUSTED
nov 03 19:58:40 raspberrypi snapclient[918]: Service 'Snapcast' of type '_snapcast._tcp' in domain 'local':
nov 03 19:58:40 raspberrypi snapclient[918]:         raspberrypi.local:1704 (192.168.1.15)
nov 03 19:58:40 raspberrypi snapclient[918]: Found server 192.168.1.15:1704
nov 03 19:58:40 raspberrypi snapclient[918]: Resolving host IP for: 192.168.1.15
nov 03 19:58:40 raspberrypi snapclient[918]: Connecting
nov 03 19:58:40 raspberrypi snapclient[918]: Connected to 192.168.1.15
nov 03 19:58:40 raspberrypi snapclient[918]: My MAC: "dc:a6:32:7a:10:c2", socket: 8
nov 03 19:58:40 raspberrypi snapclient[918]: ServerSettings - buffer: 1000, latency: 0, volume: 100, muted: 0
nov 03 19:58:40 raspberrypi snapclient[918]: Codec: flac, sampleformat: 48000:16:2
nov 03 19:58:40 raspberrypi snapclient[918]: metadata:{"STREAM":"Music"}

My guess:
We can see that in the first log (the one wich the bug occours) it connects to an weird ipv6 ip, and fails. And in the second it connects to the "good" ipv4 and succeeds.
I think that, since both snap server and client are starting up, they didn't connect to the network yet, but the snapclient found the snapserver internal/local tcp socket, and tries to connect to it.
and then we have two possibilities:

snapclient and/or snapserver gets connected to the network, and somehow disturbs/break the ongoing connection from snapclient to snapserver
or there is some bug (about permissions maybe?) for internal/local connection between snap client and server, when in the same machine.

and then it just keeps trying the same failed connection again and again.
Steps to Reproduce

have both snapclient and snapserver on your system (set up as services) -> just install the .deb files
reboot your system.
check if the snapclient failed (the bug happened)
repeat step 2 and 3 until you get the bug.

Environment details

OS: Raspbian
Snapcast version 0.22.0
Installed from .deb
snapserver have two hidden(&codec=null) pipe streams
and one meta stream, joining those 2 streams

Closing comment (2020-11-04T08:55:07Z): This is a duplicate of #518
The server is per default listening on IPv4 only (which is admittedly not the best choice for a default regarding that the server broadcasts it's IPv4 and IPv6 addresses).
You can either configure the server's IP address by adding -h 127.0.0.1 to the client or let the server listen on both IPv4 and IPv6 addresses, with bind_to_address = :::
# Stream settings #############################################################
#
[stream]
# address to listen on, can be specified multiple times
# use "0.0.0.0" to bind to any IPv4 address or :: to bind to any IPv6 address
# or "127.0.0.1" or "::1" to bind to localhost IPv4 or IPv6, respectively
# use the address of a specific network interface to just listen to and accept
# connections from that interface
bind_to_address = ::
#bind_to_address = 0.0.0.0