Fix "Address Already in Use" on Linux (Port Conflicts)
Track down what owns a busy port, decide whether to kill it or rebind, and stop TIME_WAIT from blocking your restart.
Key takeaways
- Another process already holds that port.
- Find it with sudo ss -ltnp 'sport = :8080' or sudo lsof -i :8080, then kill the stale PID or start your server on a different port.
- If nothing is listening and bind still fails, a TIME_WAIT socket is blocking it, so set SO_REUSEADDR before bind().
On this page
"Address already in use" means another socket already owns that port. Find the owner with sudo ss -ltnp 'sport = :8080' (or sudo lsof -i :8080), then either kill the stale PID or start your server on another port. If nothing is listening and bind() still fails, a TIME_WAIT socket is in the way: set SO_REUSEADDR before binding.
Verified against
ss from iproute2 (man page snapshot of August 2026), socket(7) and tcp(7) from Linux man-pages 6.19, against the man7.org manual pages and the Node.js 26 errors docs. Checked October 2026.
./myserver
error: listen tcp 0.0.0.0:8080: bind: address already in use
Node calls this EADDRINUSE, Python raises OSError: [Errno 98], Go prints the line above, and uvicorn reports [Errno 98] error while attempting to bind on address. Same kernel error underneath: bind(2) returned EADDRINUSE.
What the error actually means
A listening socket is a tuple: protocol, local address, local port. The kernel lets exactly one listening socket own a given host:port combination for a protocol at a time (unless every socket opted into SO_REUSEPORT). When your process asks to bind() to 0.0.0.0:8080 and something already holds that tuple, the kernel refuses. It is not a firewall, not DNS, and usually not permissions. Something is already listening, or a recently closed socket is still holding the port.
Two questions get you to a fix: what owns the port, and do you want that thing gone or do you want a different port.
Find the culprit
ss is the modern tool. -l listening, -t TCP, -n numeric, -p show the process:
sudo ss -ltnp 'sport = :8080'
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 511 0.0.0.0:8080 0.0.0.0:* users:(("node",pid=4821,fd=23))
PID 4821, an old node process, still holds 8080. Run ss with sudo, otherwise the Process column comes back empty for sockets you do not own. For UDP services (DNS, syslog, game servers), swap -t for -u.
lsof gives the same answer plus the user, and fuser is the quickest when you just want the PID:
sudo lsof -nP -i :8080
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 4821 kiril 23u IPv4 512377 0t0 TCP *:8080 (LISTEN)
sudo fuser 8080/tcp
8080/tcp: 4821
If the PID belongs to systemd itself, the port is socket-activated: a .socket unit owns it and will keep re-opening it. Find it with systemctl list-sockets | grep 8080 and stop the socket unit, not the service.
On Windows the equivalent is netstat -ano | findstr :8080, then taskkill /PID 4821 /F.
Kill it or move
If the process is a stale copy of your own service, kill it:
sudo kill 4821 # SIGTERM, lets it clean up
sudo kill -9 4821 # SIGKILL, only if it ignores the first
sudo kill $(sudo lsof -t -i :8080) # lookup and kill in one line
fuser -k 8080/tcp does the same. Be deliberate here: on a shared box that PID might be someone else's database. Confirm the command name before you signal anything. If the process comes straight back with a new PID, a supervisor (systemd, pm2, Docker's restart policy) is respawning it; stop it through that supervisor instead.
If the port legitimately belongs to another service, do not fight it. Change your own port: PORT=8081 ./myserver, or uvicorn main:app --port 8001.
The TIME_WAIT case: your just-stopped server can't rebind
You stop your server, immediately restart it, and get address already in use even though ss -ltn shows nothing listening. What you will see instead is a socket in TIME_WAIT:
ss -tan | grep 8080
TIME-WAIT 0 0 10.0.1.5:8080 10.0.1.9:52344
When a TCP connection closes, the side that closed first keeps the socket in TIME_WAIT so straggling packets from the old connection die out. On Linux that window is roughly a minute and is fixed in the kernel, not exposed as a sysctl. During it the kernel, by default, refuses to bind a fresh listening socket to the same address and port.
The wrong fix is to wait, or to tune tcp_fin_timeout: tcp(7) documents that setting as how long to wait for a final FIN, which is a different state. The right fix lives in your code: set SO_REUSEADDR on the listening socket before you bind. Per socket(7), it lets a socket bind "except when there is an active listening socket" on that address.
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) # before bind()
s.bind(("0.0.0.0", 8080))
s.listen()
Most frameworks set this for you. Python's http.server (allow_reuse_address = True), Go's net.Listen, Node's net, and asyncio-based servers like uvicorn all enable it, which is why you rarely hit TIME_WAIT in those. If you wrote the socket code by hand and skipped it, this is your bug.
SO_REUSEPORT is different: it lets multiple sockets bind the same port at once so several workers can each accept connections, with the kernel spreading load across them. socket(7) says it must be set on every socket, including the first, and all of them must share the same effective UID. Reach for it when you want that behavior, not as a TIME_WAIT workaround.
The error strings, and the fix for each
bind: address already in use/EADDRINUSE/[Errno 98]: a live listener.ss -ltnp, then kill or move.- Same error,
ss -ltnempty,ss -tanshowsTIME-WAIT: setSO_REUSEADDRbeforebind(). bind: permission denied/EACCESon port 80 or 443: not a conflict, a privileged port. See below.bind: cannot assign requested address/EADDRNOTAVAIL: you asked for an IP this host does not have, often a stale address in config or a bind before the interface is up.Bind for 0.0.0.0:8080 failed: port is already allocated: Docker. Another container or host process holds it.
Wildcard collisions. 0.0.0.0 means every interface on this host; 127.0.0.1 means loopback only. A socket bound to 0.0.0.0:8080 covers 127.0.0.1:8080 too, so a second process trying 127.0.0.1:8080 collides with it. When ss shows 0.0.0.0:8080 and you thought you only bound loopback, that wildcard bind is the thing in your way.
Privileged ports. Binding under 1024 as a normal user fails with EACCES. Rather than run the whole service as root, grant just the bind capability:
sudo setcap 'cap_net_bind_service=+ep' /usr/local/bin/myserver
For interpreted apps, listen high (8080) and let a reverse proxy handle 80.
Docker. docker run -p 8080:80 nginx fails with "port is already allocated", and Compose prints failed to bind host port 0.0.0.0:8080/tcp: address already in use. Same root cause, one layer up. Use ss -ltnp on the host plus docker ps to spot the container; the full walkthrough is in Docker port already allocated.
Where this breaks
None of this applies inside a container's own network namespace: ss on the host will not show a port a container bound internally, so run it with docker exec or nsenter. It also does not explain intermittent failures on outbound connections under heavy load; that is ephemeral port exhaustion, a different problem with different fixes. And on macOS, ss and fuser do not exist; use lsof -nP -iTCP:8080 -sTCP:LISTEN.
Questions people ask
How do I fix "address already in use" with nc?
nc -l 8080 fails when another listener, often a previous nc you backgrounded or left in another terminal, still holds the port. Run sudo ss -ltnp 'sport = :8080', kill the PID it prints, and retry. If the port must stay with its current owner, listen on a free one instead. Netcat cannot share a port that has an active listener.
Why does uvicorn say address already in use?
Uvicorn binds 127.0.0.1:8000 by default, so the usual cause is a second uvicorn still running: a forgotten terminal, a crashed --reload session that left a worker behind, or a container publishing 8000. Find it with sudo lsof -i :8000, kill that PID, or start on another port with uvicorn main:app --port 8001.
How do I kill whatever is using a port?
sudo kill $(sudo lsof -t -i :8080) sends SIGTERM to every process holding 8080; sudo fuser -k 8080/tcp does the same in one command. Check the process name with ss -ltnp first, because on a shared host that PID might be a database or another team's service. Use kill -9 only if SIGTERM is ignored.
The call we'd make
Run sudo ss -ltnp 'sport = :PORT' first, every time. If the owner is a stale copy of your own service, kill it and restart. If it belongs to something real, move your service to another port instead of fighting for it. If nothing is listening but you still can't bind, fix TIME_WAIT with SO_REUSEADDR in the code rather than sleeping through the timer. Most of these are a forgotten background process, and ss finds it in seconds. For the broader toolkit, see our Linux troubleshooting guide.
Sources
Cite this article
Kiril Urbonas (2026). Fix "Address Already in Use" on Linux (Port Conflicts). DevOpsNess. Updated 2026-11-11. https://www.devopsness.com/blog/fix-address-already-in-use
[Fix "Address Already in Use" on Linux (Port Conflicts)](https://www.devopsness.com/blog/fix-address-already-in-use) (Kiril Urbonas, DevOpsNess, updated 2026-11-11)
More from Linux
Explore more articles in this category
DNS Troubleshooting on Linux: A Systematic Approach
\"It's always DNS\" is a joke because the failure modes are so scattered: resolver config, caching, search domains, split DNS. Here is where to actually look.
SSH Hardening in 2026: Keys, Certificates, and Bastion Patterns
We had 140 engineers with 300 static public keys scattered across authorized_keys files nobody could audit. Moving to SSH certificates with short TTLs made access reviewable again.
SSH Tutorial: Keys, Config, and Working Remotely
Generate an SSH key, set up passwordless login, and configure aliases for the servers you use daily, all without copy-pasting yet another long command.
You might have missed
Evergreen posts worth revisiting.