mikebrady / shairport-sync

AirPlay and AirPlay 2 audio player
Other
7.29k stars 574 forks source link

Shairport-sync disappears from network if inactive for couple hours #793

Closed kospek closed 5 years ago

kospek commented 5 years ago

Hi!

I've got MusicBox running on Raspberry Pi Zero W and JustBoom DAC Zero with enabled Shairport-sync. After rPi is booted - everything looks fine: I can connect to Shairport, stream audio from both Mac and iOS devices. Music stutters from time to time, but I did not find the issue, seems to be somewhat random (CPU load is not peaking when this happens, and stuffing option is 'basic'. But this is not the main problem. Music can be played for some time (could be hours, no problem here). When after that I switch from Shairport to internal audio device and Shairport is not used (for couple hours) - it dissappears from the list of devices. I can't connect to it from Mac or iPhone, but I can reach rPi via ssh. It occurs when, for example, I turn off music at night (rPi stays turned on) and in the morning there's no Shairport-sync device available for connection. Why is it disappearing? # shairport-sync -v returns this:

alsa output device name is "default".
Version: "3.2.2-OpenSSL-Avahi-ALSA-metadata-sysconfdir:/etc"
statistics_requester status is 0.
daemon status is 0.
deamon pid file path is "/var/run/shairport-sync/shairport-sync.pid".
rtsp listening port is 5000.
udp base port is 6001.
udp port range is 100.
player name is "MusicBox".
backend is "(null)".
on-start action is "(null)".
on-stop action is "(null)".
wait-cmd status is 0.
on-start returns output is 0.
mdns backend "(null)".
stuffing option is "0" (0-basic, 1-soxr).
resync time is 0.050000 seconds.
allow a session to be interrupted: 0.
busy timeout time is 120.
drift tolerance is 0.001995 seconds.
password is "(null)".
ignore_volume_control is 0.
volume_max_db is not set
playback_mode is 0 (0-stereo, 1-mono, 1-reverse_stereo, 2-both_left, 3-both_right).
disable_synchronization is 0.
use_mmap_if_available is 1.
output_rate is 44100.
output_format is 3 (0-unknown, 1-S8, 2-U8, 3-S16, 4-S24, 5-S24_3LE, 6-S24_3BE, 7-S32).
audio backend desired buffer length is 0.150000 seconds.
audio backend latency offset is 0.000000 seconds.
audio backend silence lead-in time is -1.000000 seconds. A value -1.0 means use the default.
volume range in dB (zero means use the range specified by the mixer): 0.
zeroconf regtype is "_raop._tcp".
decoders_supported field is 1.
use_apple_decoder is 0.
alsa_use_hardware_mute is 0.
no special mdns service interface was requested.
configuration file name "/etc/shairport-sync.conf" resolves to "/etc/shairport-sync.conf".
metadata enabled is 0.
metadata pipename is "(null)".
metadata socket address is "(null)" port 0.
metadata socket packet size is "500".
get-coverart is 0.
loudness is 0.
loudness reference level is -20.000000
disable resend requests is off.
diagnostic_drop_packet_fraction is 0.000000. A value of 0.0 means no packets will be dropped deliberately.
Unable to listen on IPv4 port 5000. The error is: "Address already in use".
Unable to listen on IPv6 port 5000. The error is: "Address already in use".
fatal error: Could not establish a service on port 5000 -- program terminating. Is another instance of Shairport Sync running on this device?
Request to shut down all rtsp conversation threads
asking playing threads to stop

Power management is also turned off:

iwconfig
lo        no wireless extensions.

wlan0     IEEE 802.11  ESSID:"blabla"  
          Mode:Managed  Frequency:2.462 GHz  Access Point: blabla   
          Bit Rate=43.3 Mb/s   Tx-Power=31 dBm   
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Encryption key:off
          Power Management:off
          Link Quality=55/70  Signal level=-55 dBm  
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:0   Missed beacon:0

Sorry if this was answered, but all similar issues I've read seems to be not exactly what I'm having - music is playing, I can connect/disconnect freely as much as I want, but when Shairport is not used for some times - it becomes inactive. Thanks!

mikebrady commented 5 years ago

Thanks for the post. Well, there could be lots of reasons. The log you quote above indicates that Shairport Sync is already running, so, at least, it doesn't seem to have crashed. For instance, a possible cause may be that the advertising for it on Rendevous/Bonjour/ZEROCONF has gone off or been blocked. This can be checked at the MusicBox end with avahi-browse (in the package avahi-utils) that can show you what is being advertised by Shairport Sync. Then at the other end, on a Mac or iOS, the applications called Discovery, ("Discovery - DNS-SD Browser" in the Mac App Store) from Tildesoft, can be used to see what is "visible" to the device.

All that said, and although Shairport Sync is generally reliable, a lot of work is being done to try to make Shairport Sync more stable – please see #772 (long!). If you'd like to take part, e.g. as a tester, let us know.

kospek commented 5 years ago

okay, so I've downloaded Discovery app and tried to find Shairport when pi just booted up. I've found it, and this what Discovery showed me:

SomeID@MusicBox._raop._tcp.local.
Remote Audio Output Protocol (AirTunes)

MusicBox.local:5000
192.168.ip.addr:5000
mac::addr:5000

am = ShairportSync
ch = 2
cn = 0,1
da = true
ek = 1
et = 0,1
fv = 76400.10
pw = false
sf = 0x4
sr = 44100
ss = 16
sv = false
tp = TCP,UDP
txtvers = 1
vn = 65537
vs = 105.1

But at the morning, when I could not connect to Shairport-sync standart way - Discovery did not find anything either. Nor any other service that was turned on in musicbox (i.e. spotify connect). And I can still reach rPi via ssh. I need now to check it from MusicBox side via avahi-browse?

mikebrady commented 5 years ago

Thanks for the update. Yes, exactly — with avahi-browse you can see what the Shairport Sync device is advertising. If it is advertising Shairport Sync and the Mac (?) isn’t seeing it, it points to some kind of network issue. If it’s not advertising, then it’s a local issue.

kospek commented 5 years ago

I am not sure if i am using avahi-browse correctly. I am not very familiar with linux or command lines I've ssh-ed to the Pi and entered this command (when I can't connect to shairport-sync): @MusicBox:~# avahi-browse -d local -a --resolve --no-db-lookup I used instructions from this website: https://www.ibm.com/support/knowledgecenter/en/SSB2MG_4.6.0/com.ibm.ips.doc/concepts/gx_gv_using_avahi.htm Nothing seems to happen at all. Pi stops responding, command line does not react on any command. If I add an option -t it looks like command is executed immediately, but nothing is returned to me. Pi just waits for next command. UPDATE: After I restart rPi command above gave some results (I removed --no-db-lookup option and added -t).

=  wlan0 IPv6 someId@MusicBox                         AirTunes Remote Audio local
   hostname = [MusicBox.local]
   address = [addr]
   port = [5000]
   txt = ["pw=false" "txtvers=1" "ch=2" "cn=0,1" "ek=1" "et=0,1" "sv=false" "da=true" "sr=44100" "ss=16" "vn=65537" "tp=TCP,UDP" "vs=105.1" "am=ShairportSync" "fv=76400.10" "sf=0x4"]
=  wlan0 IPv4 someid@MusicBox                         AirTunes Remote Audio local
   hostname = [MusicBox.local]
   address = [192.168.ip.addr]
   port = [5000]
   txt = ["pw=false" "txtvers=1" "ch=2" "cn=0,1" "ek=1" "et=0,1" "sv=false" "da=true" "sr=44100" "ss=16" "vn=65537" "tp=TCP,UDP" "vs=105.1" "am=ShairportSync" "fv=76400.10" "sf=0x4"]

Also I've noticed this: When Shairport is unavailable, avahi-browse did not even show me my Chromecast, connected to the same network. "Discovery" app on the phone shows it all the time.

mikebrady commented 5 years ago

Thanks. Let me have a think about this for a few hours.

mikebrady commented 5 years ago

So, I had a quick look. The command I use is:

$ avahi-browse -ar

and this displays everything that can be seen at the computer, but it stays working, and doesn't return to the prompt until you stop it by entering control-C.

It should always work, and it would be very unusual for there to be nothing to see on a computer that's connected to a network.

If avahi-browse shows the Chromecast when everything is working normally, and doesn't when Shairport Sync is not visible, it would seems to point to some kind of a network connectivity issue. Possibly a firewall setting or something similar might be causing a problem.

kospek commented 5 years ago

Thanks, I'll check this too. In meantime I've noticed this: I've turned on rPi today around 12.30. Used Shairport for a while and went outside. I've returned back home and tried to connect in the evening, at 22.30 - and Shairport is available, and works! Could it somehow be affected by the change of dates? I usually go to bed around 23.00, or at least stop using Shairport and don't bother checking it after midnight. I will try to use the command when Shairport is offline, which is not right now. Even, as I mentioned above, I did not use it for around 8 hours.

kospek commented 5 years ago

Short update: Now Shairport does not dissappear... It was turned all night and in the morning it is still available for connect.

kospek commented 5 years ago

I don't know what happens.. Shairport still works fine. I did nothing except things above.. I am positivly surprised but I don't understand this. When I first installed Music Box - for couple of days Shairport disappeared as described. Now it works all the time (except once I had to restart it during the day because it stoped casting sound when I skipped episode intro in Netflix. It only happened once, so I guess no big deal). Anyways, thank you very much, @mikebrady. Shairport-sync is awesome! I will write update in case it happens again :)

mikebrady commented 5 years ago

Would it be okay to close this issue?

kospek commented 5 years ago

@mikebrady yes, I guess. Works seamless now. Did not restart Pi since last time I wrote. Thanks for help!