mikebrady / shairport-sync

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

[Problem]: number of open sockets keep growing indefinitly #1567

Closed lstrojny closed 2 years ago

lstrojny commented 2 years ago

What happened?

When a client connects to shairport-sync and then eventually disconnects, the socket stays open and will eventually exhaust the nofiles limit on the system.

Here is how to trigger the issue (use lsof | grep shairport | wc -l to count the number of open files on the server).

telnet dodecaphonism 7000
Trying 10.1.25.10...
Connected to dodecaphonism.
Escape character is '^]'.
OPTIONS rtsp://localhost RTSP/1.0

RTSP/1.0 200 OK
Server: AirTunes/366.0
Public: ANNOUNCE, SETUP, RECORD, PAUSE, FLUSH, FLUSHBUFFERED, TEARDOWN, OPTIONS, POST, GET, PUT

TEARDOWN rtsp://localhost RTSP/1.0

RTSP/1.0 451 Unavailable
Server: AirTunes/366.0
Connection: close

^]
telnet>

This is what the state of the connections is shortly after quitting telnet:

[...]
shairport  5040  5047 shairport shairport-sync   24u     IPv4    1090080       0t0        TCP raspberrypi.local:bbs->MacBook-Pro:59346 (CLOSE_WAIT)
shairport  5040  5047 shairport shairport-sync   25u     IPv4    1094833       0t0        TCP raspberrypi.local:bbs->MacBook-Pro:60095 (CLOSE_WAIT)

Expectation would be that once telnet disconnects the socket on the server side is closed as well.

Relevant log output

shairport  5040  5047 shairport shairport-sync    9u     sock        0,8       0t0    1078272 protocol: TCP
shairport  5040  5047 shairport shairport-sync   10u     sock        0,8       0t0    1083393 protocol: TCP
shairport  5040  5047 shairport shairport-sync   11u     sock        0,8       0t0    1083394 protocol: TCP
shairport  5040  5047 shairport shairport-sync   12u     sock        0,8       0t0    1083590 protocol: TCP
shairport  5040  5047 shairport shairport-sync   13u     sock        0,8       0t0    1083672 protocol: TCP
shairport  5040  5047 shairport shairport-sync   14u     sock        0,8       0t0    1083673 protocol: TCP
shairport  5040  5047 shairport shairport-sync   15u     sock        0,8       0t0    1083687 protocol: TCP
shairport  5040  5047 shairport shairport-sync   16u     sock        0,8       0t0    1083927 protocol: TCP
shairport  5040  5047 shairport shairport-sync   17u     sock        0,8       0t0    1083931 protocol: TCP
shairport  5040  5047 shairport shairport-sync   18u     sock        0,8       0t0    1083945 protocol: TCP
shairport  5040  5047 shairport shairport-sync   19u     sock        0,8       0t0    1084015 protocol: TCP
shairport  5040  5047 shairport shairport-sync   20u     sock        0,8       0t0    1084092 protocol: TCP

Configuration Information.

     0.001043125 "shairport.c:2057" >> Display Config Start.
     0.004572552 "shairport.c:2057"
     0.000074271 "shairport.c:2057" From "uname -a":
     0.000024948 "shairport.c:2057"  Linux dodecaphonism 5.15.76-v7+ #1596 SMP Mon Oct 31 17:08:20 GMT 2022 armv7l GNU/Linux
     0.010415989 "shairport.c:2057"
     0.000077813 "shairport.c:2057" From /etc/os-release:
     0.000026146 "shairport.c:2057"  Raspbian GNU/Linux 11 (bullseye)
     0.006834844 "shairport.c:2057"
     0.000078854 "shairport.c:2057" From /sys/firmware/devicetree/base/model:
     0.000025104 "shairport.c:2057"  Raspberry Pi 3 Model B Rev 1.2
     0.000090833 "shairport.c:2057"
     0.000024219 "shairport.c:2057" Shairport Sync Version String:
     0.000022604 "shairport.c:2057"  4.1-4-g99e76fdf-AirPlay2-OpenSSL-Avahi-ALSA-soxr-metadata-sysconfdir:/etc
     0.000025573 "shairport.c:2057"
     0.000020313 "shairport.c:2057" Command Line:
     0.000020937 "shairport.c:2057"  shairport-sync --displayConfig
     0.000080990 "shairport.c:2057"
     0.000023333 "shairport.c:2057" Configuration File:
     0.000021771 "shairport.c:2057"  /etc/shairport-sync.conf
     0.000021927 "shairport.c:2057"
     0.000183125 "shairport.c:2057" Configuration File Settings:
     0.000026094 "shairport.c:2057"  general :
     0.000022135 "shairport.c:2057"  {
     0.000021354 "shairport.c:2057"    name = "Lautsprecher im Büro";
     0.000022084 "shairport.c:2057"    interpolation = "soxr";
     0.000021875 "shairport.c:2057"    output_backend = "alsa";
     0.000021770 "shairport.c:2057"    mdns_backend = "avahi";
     0.000021511 "shairport.c:2057"  };
     0.000021250 "shairport.c:2057"  diagnostics :
     0.000020989 "shairport.c:2057"  {
     0.000020990 "shairport.c:2057"    statistics = "yes";
     0.000112500 "shairport.c:2057"    log_verbosity = 1;
     0.000025156 "shairport.c:2057"  };
     0.000022136 "shairport.c:2057"
     0.000020520 "shairport.c:2057" >> Display Config End.
     0.000021875 "shairport.c:2059" >> Goodbye!
     0.000051459 "shairport.c:1670" normal exit

How did you install Shairport Sync?

Built from source

Check previous issues

mikebrady commented 2 years ago

Thanks for the interesting report.

I can reproduce the issue, thanks.

mikebrady commented 2 years ago

Thanks again for the report. An update with that bug fixed (I believe) has been pushed into the development branch.

If you got a chance to check it out, that would be great. That bug has been there for a long time!

lstrojny commented 2 years ago

Fix looks good to me. Tried running the latest development version and despite shairport being hammered by monitoring probes, number of open files stay constant. Thank you for looking into a somewhat esoteric issue and thank you very much for shairport in general.