What's Eating Port 5000

MMM.. FOOD

I’ve been playing around with one of those new M1 Max Macbooks and it’s been fun. My windows open really fast and my terminal emulator doesn’t jank the whole OS anymore, so I’ve been super productive.

Anyway, I was trying to get some stuff setup locally, but I ran into a weird problem when running one of the commands:

$ make redacted-redacted-redacted-redacted-redacted
...
docker: Error response from daemon: Ports are not available: listen tcp 0.0.0.0:5000: bind: address already in use.
make: *** [redacted-redacted-redacted-redacted-redacted] Error 125

The computer was mostly a clean slate at this point and I wasn’t running any servers of my own (especially not the soundless soundboard that’s usually running on my other machines).

I Up+Entered a few more times, just to be sure. The same thing happened each time.

$ make redacted-redacted-redacted-redacted-redacted
docker: Error response from daemon: Ports are not available: listen tcp 0.0.0.0:5000: bind: address already in use.
$ make redacted-redacted-redacted-redacted-redacted
docker: Error response from daemon: Ports are not available: listen tcp 0.0.0.0:5000: bind: address already in use.
$ make redacted-redacted-redacted-redacted-redacted
docker: Error response from daemon: Ports are not available: listen tcp 0.0.0.0:5000: bind: address already in use.

lsof, my favourite Unix-like tool of all time, told me that the port is bound to a MacOS system command:

$ lsof -nP -i:5000
COMMAND     PID   USER   FD   TYPE            DEVICE SIZE/OFF NODE NAME
ControlCe 32275    foo   16u  IPv4 0x813fd83221ca671      0t0  TCP *:5000 (LISTEN)
ControlCe 32275    foo   17u  IPv6 0x813fd830fa1da99      0t0  TCP *:5000 (LISTEN)
$ ps 32275
  PID   TT  STAT      TIME COMMAND
32275   ??  S      0:14.36 /System/Library/CoreServices/ControlCenter.app/Contents/MacOS/ControlCenter

bfad figured out that it’s related to AirPlay Receiver, which listens for AirPlay requests or something. It’s also listening on port 7000.

If I stop that receiver service, start a server of my own on port 5000, and then restart the receiver, it listens on 56671 instead. I wonder how it’s choosing that port.