Networking: Thousands of sockets in CLOSE_WAIT — the application is not closing its side of the connection
The other end closed the connection, but your program never called close(), so the socket stays open.
many CLOSE_WAIT connectionssockets stuck in CLOSE_WAITCLOSE_WAIT leaktcp CLOSE_WAIT too many Meaning
CLOSE_WAIT is entirely local: the kernel is waiting for the application to close. It points to a connection or file-descriptor leak (missing close()/finally, unreleased HTTP responses, pooled connections). Find the process with ss -tanp, fix the leak, and watch for "Too many open files".
Common causes
- Application never closes sockets (leak)
- HTTP client response body not consumed/closed
- Connection pool not releasing
- Exception paths skip close()
- Thread stuck so it never reaches close()
⚡ Quick fix
- Find the owner:
ss -tanp state close-wait - Fix the leak: close in finally/using/defer
- Restart as a stopgap and monitor the count
Detailed fix by platform
Linux
ss -tanp state close-wait | awk "{print $NF}" | sort | uniq -c | sort -rn | head
How to diagnose
- State — CLOSE_WAIT?
- Process — Which one?
- FD limit — Near?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- arp -a shows (incomplete) Networking: `arp -n` shows (incomplete) / Destination Host Unreachable — no ARP reply from the next hop
- Cannot assign requested address (EADDRNOTAVAIL) Networking: connect: Cannot assign requested address — ephemeral port range exhausted by TIME_WAIT connections
- Connections hang on large transfers (PMTU black hole) Networking: SSH/HTTPS connects but hangs on large data — path MTU discovery black hole
Most viewed in Networking
- Native VLAN mismatch / wrong VLAN, no connectivity Networking: %CDP-4-NATIVE_VLAN_MISMATCH / device on the wrong VLAN can't reach the gateway
- Port err-disabled (psecure-violation) Networking: %PM-4-ERR_DISABLE: psecure-violation error detected on Gi0/5, putting Gi0/5 in err-disable state
- Rogue DHCP server hands out wrong gateway/DNS Networking: Clients receive the wrong default gateway or DNS server — a rogue DHCP server (often a home router) answers first
Other ways to find it
Where this error sits
Origin: Network. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 5 Nov 2026