debugMinorpending
EADDRINUSE -- port already in use on server restart
Viewed 0 times
EADDRINUSEport in uselsofkill processTIME_WAITSO_REUSEADDR
nodejspythonterminal
Error Messages
Problem
Node.js or Python server fails to start with EADDRINUSE or Address already in use. The port is still held by a previous process that did not shut down cleanly.
Solution
(1) Find the process: lsof -i :3000 (macOS/Linux) or netstat -tlnp | grep 3000. (2) Kill it: kill PID (graceful) or kill -9 PID (force). (3) Prevent: handle SIGTERM in your app to close the server. (4) In development: use a different port or set SO_REUSEADDR (net.createServer with server.listen({ port, reusePort: true })). (5) nodemon/ts-node-dev handle this automatically.
Why
TCP sockets enter TIME_WAIT state after close to handle delayed packets. The OS holds the port for ~60 seconds. SO_REUSEADDR allows binding to a port in TIME_WAIT.
Revisions (0)
No revisions yet.