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
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.
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
- Open port checker: Is a TCP port open, closed or filtered from the internet?
Related reading
- ERR_ADDRESS_UNREACHABLE: how to fix it: Fix ERR_ADDRESS_UNREACHABLE: no route to the server, wrong IP in DNS, IPv6 problems, private addresses and firewalls, for visitors and server owners.
- PostgreSQL connection refused: how to fix it: Fix PostgreSQL connection refused on port 5432: server not running, listen_addresses, pg_hba.conf, Docker hostnames and firewalls, with commands for every case.
- ERR_UNSAFE_PORT: how to fix it: Fix ERR_UNSAFE_PORT: Chrome blocks web requests to ports used by other protocols (SMTP, IRC, SIP). Move your service to a safe port or allow it locally.
- ENOTFOUND getaddrinfo: how to fix DNS errors in Node.js: Fix getaddrinfo ENOTFOUND and EAI_AGAIN in Node.js: wrong hostnames, a URL passed as host, container DNS and thread pool exhaustion, with test commands.
- Node.js event loop lag: how to measure and fix it: Measure and fix Node.js event loop lag: monitorEventLoopDelay, CPU profiles, synchronous code, big JSON and worker threads, with thresholds that matter.
- PostgreSQL "too many clients already": how to fix it: Fix PostgreSQL FATAL: sorry, too many clients already. See who holds connections, stop leaks, add PgBouncer and size max_connections the right way.
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.