- 论坛徽章:
- 0
|
回复 #1 gi1et 的帖子
tomcat httpclient CLOSE_WAIT2009-07-02 22:18From:
http://bbs.linuxpk.com/thread-16900-1-1.html
问题终于解决了, 原来不是apache的问题, 是resin上的程序使用了httpclient做为客户端搞的.
netstat -antp的时候, 发现8080端口的CLOSE_WAIT连接都是属于进程java的, 重启resin就释放.
解决办法: 在调用httpclient时加入一行:
httpmethod.setRequestHeader("Connection", "close");
让这个socket在请求完毕后就关闭.
http://tw.myblog.yahoo.com/robin ... =1430&next=1363
***************************************************************************
CLOSE_WAIT狀態的生成原因
如果是CLIENT端主動斷掉當前連接的話,那麼雙方關閉這個TCP連接共需要四個packet:
Client ---> FIN ---> Server
Client <--- ACK <--- Server
這時候Client端處於FIN_WAIT_2狀態;而Server 程序處於CLOSE_WAIT狀態。
Client <--- FIN <--- Server
這時Server 發送FIN給Client,Server 就成為LAST_ACK狀態。
Client ---> ACK ---> Server
Client回應了ACK,那麼Server 才會成為CLOSED狀態。
******************************************************************************
解決方法:
1.(暫時生效,重新啓動 linux 後,會還原成預設值)
sysctl -w net.ipv4.tcp_fin_timeout=30
sysctl -w net.ipv4.tcp_keepalive_time=1800
sysctl -w net.ipv4.tcp_keepalive_probes=2
sysctl -w net.ipv4.tcp_keepalive_intvl=2
2.(永久生效)
vi /etc/sysctl.conf
# Decrease the time default value for tcp_fin_timeout connection
net.ipv4.tcp_fin_timeout = 30
# Decrease the time default value for tcp_keepalive_time connection
net.ipv4.tcp_keepalive_time = 1800
# 探測次數
net.ipv4.tcp_keepalive_probes=2
# 探測間隔秒數
net.ipv4.tcp_keepalive_intvl=2
編輯完 /etc/sysctl.conf,要重啓network 才會生效
[root@temp /]# /etc/rc.d/init.d/network restart
**********************************************************************************
PS: 發生CLOSE_WAIT 的原因,可能在於程式內 一端的Socket使用close後,另一端的Socket沒有使用close.檢查一下代碼內是否有 Server端在某些異常情況時,沒有關閉Socket,將之修改,應可改正此一問題 |
|