Resolving The Problem Of Port 5000 Already Being In Use
A Quick Tutorial On macOS Monterey #
Are you experiencing a problem where you are unable to start a service on your Mac that is using port 5000?
Maybe you are a flask developer and banging your head against the wall why your app won’t start?
This post provides the background of why port 5000 is already being in use and blocking your application and is walking you through the options and steps on how to resolve it.
It so happened to me recently while switching to a new MacBook and trying to get a flask app running again.
When starting the app I always got the following message:
Ports are not available: listen tcp 0.0.0.0:5000: bind: address already in use
This is the machine I am working on:
- macOS Monterey Version 12.0.1
- Macbook Pro (16-inch, 2021)
- Apple M1 Max
My first action was to check what is using port 5000 by calling lsof -i:5000
in the terminal.
~ % lsof -i:5000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
ControlCe 20931 --------- 22u IPv4 0xa77c95dcd16d38f7 0t0 TCP *:commplex-main (LISTEN)
ControlCe 20931 --------- 23u IPv6 0xa77c95dcd16c66df 0t0 TCP *:commplex-main (LISTEN)
The result: One service with the name “ControlCentre” and a process ID of 20931 is already using port 5000.
Check the resources below to read up on what the Control Centre is actually good for. Here is a quick quote from the manual:
Control Centre on Mac gives you quick access to key macOS settings — such as volume, brightness, Wi-Fi or Focus — and indicates when your Mac is using a camera or microphone. You can customise Control Centre to add other items, such as accessibility shortcuts or Fast User switching.
Well, if you try to kill the process with kill -9 20931
, don’t even bother. It will restart immediately again.
There are two options:
- Use another port for your application.
- Dig a little deeper and maybe find a specific setting.
I haven chosen the second option and found the solution in Apples Developer Forum.
Under “System Preferences” select “Sharing”
In the list on the left, there is an option “AirPlay Receiver”.
This needs to be deactivated.
That’s all about it. Now, start your application that is using port 5000 and everything is running smoothly again.
Of course, this solution is only an option if you don’t need AirPlay Receiver.
What is an AirPlay Receiver your are asking? It is a new feature that came along with macOS Monterey. Here is a quick explanation from Apples website:
Turn on AirPlay Receiver to receive video and audio content from any nearby Mac, iPhone or iPad on the same network.
Actually this is a feature I was longing for, for a very long time and finally Apple is shipping it with the new OS.
Hopefully this post was able to save you some time in debugging and finding the proper solution.
Thank you for reading!
- If you enjoyed this, please follow me on Medium
- Buy me a coffee to keep me going
- Support me and other Medium writers by signing up here
https://twissmueller.medium.com/membership