Home > OS >  M1 mac process keeps autogenerating and locks my port
M1 mac process keeps autogenerating and locks my port

Time:11-08

I tried to run my express app with port 5000, and I found that some processes are already using it:

↳ lsof -i :5000
COMMAND    PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
ControlCe 1677 user   32u  IPv4 0x728ff8e52d51c6dd      0t0  TCP *:commplex-main (LISTEN)
ControlCe 1677 user   33u  IPv6 0x728ff8e51d98ec65      0t0  TCP *:commplex-main (LISTEN)

So I simply tried to kill them to unlock the port, but it won't work because once I run the kill (or sudo kill) command, the process with the new PID locks my 5000 port again.

↳ kill 1677
↳ lsof -i :5000
COMMAND    PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
ControlCe 2159 user   32u  IPv4 0x728ff8e52fd4dc1d      0t0  TCP *:commplex-main (LISTEN)
ControlCe 2159 user   33u  IPv6 0x728ff8e51d98d0e5      0t0  TCP *:commplex-main (LISTEN)

I killed the process 1677, and then a new process (with PID 2159) came out. It has different PID and different Device. I already tried to restart my laptop but it was also not working. Has anyone with M1 or Intel Mac experienced a similar issue like this?

Edit: I think ControlCe means Control Center?

CodePudding user response:

Turning off the AirPlay Receiver (listens on port 5000) fixed the issue for me:

Go to System Preference --> Sharing --> uncheck off the AirPlay Receiver

For more details: https://utf9k.net/questions/macos-port-5000-monterey/

CodePudding user response:

I had this exact same problem too. I think it's because of macOS Monterey (12.0). To fix it, run this command in a terminal:

pkill ControlCenter; nc -l 5000

...and then hit Ctrl C a few seconds later.

What that will do, is it will kill the ControlCenter processes, and then it will start an empty netcat TCP server listening on the very port used by ControlCenter, i.e., 5000. That way, because ControlCenter automatically restarts when it's killed, it will allocate that port before ControlCenter starts, so that when it does start, it will find that its port is in use and it will die.

  • Related