1. 定位是哪个进程在泄漏
ss -tanp state close-wait | awk '{print $6}' | sort | uniq -c | sort -rn
2. 看 fd 与连接的对应关系
ls -l /proc//fd | wc -l
lsof -p | grep CLOSE_WAIT
```
- 泄漏进程拿到后,抓 thread dump(
jstack / py-spy dump / goroutine profile)找阻塞点;
- 对照连接的对端端口,判断来自上游服务还是自己的连接池;
- 检查 HTTP 客户端三件套:read timeout 是否设置、池的 idle eviction 是否小于服务端 keep-alive 超时、错误路径是否复用同一连接对象。
修复要点
- 所有资源用
try-with-resources / with / defer 管理,杜绝手动 close;
- 每个 HTTP 调用显式设 connect/read timeout;
- 连接池开启