Home/Troubleshooting/Address already in use on Mac: port 5000 (or another port) is taken when starting a server

Address already in use on Mac: port 5000 (or another port) is taken when starting a server

Updated · airankrush

Symptom

Starting a development server or container reports EADDRINUSE, address already in use or port is already allocated, and the service does not come up, even though you have not started anything else.

Possible causes (most common first)

  1. A process from the previous run did not exit cleanly and still holds the port in the background. Common after a terminal window was closed outright or a remote session dropped.
  2. Port 5000 or 7000 is used by AirPlay in macOS. In Apple's port list, both TCP ports are listed under AirPlay.
  3. A Docker container or another project maps the same port.
  4. The port is held by a system service or by the platform's remote-access or management components.

Troubleshooting steps (easiest first)

  1. Find out who is listening

    Run lsof -nP -iTCP:5000 -sTCP:LISTEN in Terminal (replace 5000 with your port). The output includes the process name and process ID. If it is your own node, python, java or similar, it is a leftover process. If it is a Docker-related process, use docker ps to see which container maps the port.

  2. Your own leftover process: end it normally

    Once you are sure you started the process, end it with kill followed by the process ID, then start the service again. If you usually run services inside tmux sessions, run tmux ls first to see whether an old session is still running the same thing.

  3. 5000 and 7000: changing port is the easiest fix

    Both ports belong to AirPlay in Apple's port list. Frameworks such as Flask default to 5000, so collisions are common on a Mac. Giving your own service a different port is the most reliable fix, for example flask run --port 5001. System Settings has a switch for AirPlay Receiver that you can turn off to free the port, but its location changes between macOS versions and Apple notes the option may be unavailable on a managed Mac, so we do not recommend relying on it.

  4. Do not end processes you do not recognise

    A rented machine runs background programs that handle remote connection and device management. If lsof shows a process name you do not recognise, or one not owned by your account, do not end it; you may cut your own remote connection. Move your service to another port and send the process name to support to confirm.

  5. Make the port configurable

    For long-running services, do not hard-code the port. Set it through an environment variable or a config file so that moving machines means changing one place. For local debugging, binding to 127.0.0.1 is enough. Exposing a port to the outside requires changing network configuration, which is not something you may do on your own.

When to contact support directly

If the port is held by a process you do not recognise, or your own process is relaunched the moment you end it, contact support on Contact support. Include your machine ID, the port number and the full lsof output line. If you need a port on the machine to be reachable from the public internet, likewise ask support first whether it is possible. Do not set up port mapping or tunnelling tools yourself.

Pricing and availability: see the plans page · Help center (中文) · Refund policy (中文) · Telegram Contact support

Back to home · All troubleshooting pages