Skip to content

Troubleshooting guide

EADDRINUSE: address already in use and how to fix it

Your server tried to listen on a port something else already holds. The fix is usually to find that process, and it is often an older copy of your own app.

3 min read11 sectionsUpdated

On this page

Key points

  • Find the holder with lsof or ss.
  • A previous copy of the same app is the usual culprit.
  • Graceful shutdown stops it recurring on deploys.
  • TIME_WAIT rarely blocks listeners with SO_REUSEADDR on.

What it means

Binding a listening socket requires the address and port to be free. EADDRINUSE is the operating system refusing a second listener. In Node.js this surfaces as an unhandled error event on the server and typically crashes the process.

Common causes

  • A previous process still running, perhaps left over by a dev watcher or a crashed terminal.
  • Two services configured for one port.
  • Restart races, where the new process starts before the old has exited.
  • A process manager running multiple copies without clustering.

Diagnose it

Identify the process and how long it has been running.

bash
# Who is listening on 3000?
sudo lsof -nP -iTCP:3000 -sTCP:LISTEN
sudo ss -ltnp | grep ':3000'

# How long has it been there, and what started it?
ps -o pid,ppid,etime,cmd -p PID

# Windows equivalent
netstat -ano | findstr :3000

Fixes

Stop the old process with kill PID, using -9 only if it refuses. Be careful with commands that kill everything touching a port, because those can also kill unrelated clients of that port. Choose the port through configuration. Implement graceful shutdown so a process stops listening on SIGTERM. In production, let systemd or a process manager handle restart order, and use SO_REUSEPORT or a load balancer when you want zero-downtime swaps.

Handling the error in code

Listen errors should be explicit. In Node.js, attach a handler with server.on('error', ...), log the port, and exit with a non-zero status, so the process manager knows that the start failed. Do not retry silently on another port in production, because the load balancer still sends traffic to the configured one. For development, picking a free port automatically is fine as long as the chosen port is printed clearly.

Catch it automatically

This often shows up as a crash loop right after deployment. Alert on restart counts, and confirm with an uptime check after each release. Look at zero-downtime deployments to avoid it by design.

Frequently asked questions

Why does nodemon cause EADDRINUSE?

It restarts faster than the old process exits. Handle SIGTERM and SIGUSR2 and close the server first.

How do I kill a process on a port?

Find its PID with lsof -ti tcp:PORT -sTCP:LISTEN, then send kill to that PID.

Does SO_REUSEADDR allow two listeners?

No. It allows rebinding past TIME_WAIT. SO_REUSEPORT is what permits several listeners.

Check it now, free

Watch your own site and services with VitalRix

Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.