Other EADDRINUSEMedium

'Address Already in Use' Error: How to Find and Free a Port

This article explains why the 'Address already in use' error occurs and provides proven commands to identify and free a busy port on any operating system.

Updated at April 6, 2026
5-10 min
Easy
FixPedia Team
Применимо к:Windows 10/11macOS 12+Linux (all distributions)Node.js / Docker / Python applications

What the EADDRINUSE Error Means

The Error: Address already in use message (or EADDRINUSE, listen EADDRINUSE: address already in use) occurs when an application attempts to bind to a network port that is already being listened on by another program. In the TCP/IP stack, a single IP address and port combination can only be assigned to one process at a time. If the socket is already occupied, the operating system rejects the startup request to prevent routing conflicts for incoming traffic. You will most commonly encounter this issue when running local development servers, databases (MySQL, PostgreSQL), proxy servers, or Docker containers.

Common Causes

  • Conflict with a system service. Standard ports (80, 443, 3306, 5432) are often occupied by web servers, databases, or utilities like IIS and Apache.
  • Stuck background process. The application may have crashed, but its process remains in memory and hasn't released the network socket.
  • TIME_WAIT state. After a connection closes, the OS temporarily reserves the port (usually for 1–4 minutes) to process any remaining buffered packets.
  • Concurrent execution. You accidentally launched a second instance of the same application, and both are trying to bind to the same port.

How to Fix It

Method 1: Diagnose via Terminal

First, you need to identify exactly which process is blocking the port. Open your command prompt or terminal and run the command appropriate for your OS. Replace 8080 with your actual port number.

Windows (PowerShell / CMD run as Administrator):

netstat -ano | findstr :8080

The output will show the LISTENING status and the PID (in the last column). Note this number.

Linux / macOS:

sudo lsof -i :8080
# or
sudo ss -tulpn | grep :8080

The command will display the process name and its PID under the PID/Program name column.

Method 2: Safely Terminate the Blocking Process

Once you have the process identifier, you can forcefully stop it.

⚠️ Important: Ensure the process you are terminating is not a critical system component (e.g., svchost.exe or systemd-resolved). Stopping these services can disrupt network connectivity.

Windows:

taskkill /PID 1234 /F

The /F flag ensures forceful termination even if the process is unresponsive.

Linux / macOS:

kill -9 1234

If the service is managed by a process manager, it's better to use the standard commands: sudo systemctl stop <service_name>.

Method 3: Reassign the Port in Configuration

If freeing the port isn't possible or it's required by another critical application, change the listening port in your application's configuration.

  1. Open the configuration file (e.g., docker-compose.yml, .env, config.json, or server.js).
  2. Locate the port, PORT, or LISTEN_PORT parameter.
  3. Change the value to an available port (e.g., 8081 or 3001).
  4. Restart the application.

For most Node.js/Python projects, it's enough to set an environment variable before running:

export PORT=3001 && node server.js  # Linux/macOS
set PORT=3001 && node server.js     # Windows CMD
$env:PORT="3001"; node server.js    # Windows PowerShell

Prevention

To avoid encountering this error again, follow these best practices:

  • Use dynamic port allocation. For local development, configure your applications to automatically select an available port (using flags like --port 0 or setting port: "auto").
  • Handle shutdown gracefully. In your server code, always attach a SIGINT/SIGTERM signal handler that properly closes connections (server.close()) instead of abruptly killing the process.
  • Check ports before deployment. Add a preliminary port availability check to your startup scripts using nc -z localhost <port> or the PowerShell equivalent Test-NetConnection.
  • Isolate environments. Run your projects in Docker containers with port mapping (-p 8080:3000) to avoid conflicts on the host machine.

F.A.Q.

How do I find out which program is using a specific port?
Can I force free a port without restarting my computer?
Why does a port remain busy even after closing the application?

Hints

Identify the Port Number and OS
Find the Blocking Process
Terminate the Process
Restart the Application

Did this article help you solve the problem?

FixPedia

Free encyclopedia for fixing errors. Step-by-step guides for Windows, Linux, macOS and more.

© 2026 FixPedia. All materials are available for free.

Made with for the community