tomcat的CLOSE_WAIT是怎麼回事
tcp 1 0 ::ffff:127.0.0.1:8080 ::ffff:127.0.0.1:48220 CLOSE_WAIT 4444/java
tcp 0 0 ::ffff:127.0.0.1:48219 ::ffff:127.0.0.1:3306 ESTABLISHED 4444/java
tcp 1 0 ::ffff:127.0.0.1:8080 ::ffff:127.0.0.1:48255 CLOSE_WAIT 4444/java
tcp 1 0 ::ffff:127.0.0.1:8080 ::ffff:127.0.0.1:48254 CLOSE_WAIT 4444/java
tcp 1 0 ::ffff:127.0.0.1:8080 ::ffff:127.0.0.1:48249 CLOSE_WAIT 4444/java
tcp 1 0 ::ffff:127.0.0.1:8080 ::ffff:127.0.0.1:48247 CLOSE_WAIT 4444/java
tcp 1 0 ::ffff:127.0.0.1:8080 ::ffff:127.0.0.1:48246 CLOSE_WAIT 4444/java
tcp 1 0 ::ffff:127.0.0.1:8080 ::ffff:127.0.0.1:48244 CLOSE_WAIT 4444/java
tcp 1 0 ::ffff:127.0.0.1:8080 ::ffff:127.0.0.1:48242 CLOSE_WAIT 4444/java
tcp 1 0 ::ffff:127.0.0.1:8080 ::ffff:127.0.0.1:48240 CLOSE_WAIT 4444/java
tcp 1 0 ::ffff:127.0.0.1:8080 ::ffff:127.0.0.1:48239 CLOSE_WAIT 4444/java
tcp 1 0 ::ffff:127.0.0.1:8080 ::ffff:127.0.0.1:48236 CLOSE_WAIT 4444/java
tcp 1 0 ::ffff:127.0.0.1:8080 ::ffff:127.0.0.1:48235 CLOSE_WAIT 4444/java
tcp 1 0 ::ffff:127.0.0.1:8080 ::ffff:127.0.0.1:48234 CLOSE_WAIT 4444/java
tcp 1 0 ::ffff:127.0.0.1:8080 ::ffff:127.0.0.1:48233 CLOSE_WAIT 4444/java
tcp 1 0 ::ffff:127.0.0.1:8080 ::ffff:127.0.0.1:48228 CLOSE_WAIT 4444/java
tcp 1 0 ::ffff:127.0.0.1:8080 ::ffff:127.0.0.1:48226 CLOSE_WAIT 4444/java
tcp 1 0 ::ffff:127.0.0.1:8080 ::ffff:127.0.0.1:48225 CLOSE_WAIT 4444/java
tcp 1 0 ::ffff:127.0.0.1:8080 ::ffff:127.0.0.1:48286 CLOSE_WAIT 4444/java
tcp 1 0 ::ffff:127.0.0.1:8080 ::ffff:127.0.0.1:48285 CLOSE_WAIT 4444/java
tcp 1 0 ::ffff:127.0.0.1:8080 ::ffff:127.0.0.1:48284 CLOSE_WAIT 4444/java
tcp 1 0 ::ffff:127.0.0.1:8080 ::ffff:127.0.0.1:48283 CLOSE_WAIT 4444/java
tcp 1 0 ::ffff:127.0.0.1:8080 ::ffff:127.0.0.1:48278 CLOSE_WAIT 4444/java
tcp 1 0 ::ffff:127.0.0.1:8080 ::ffff:127.0.0.1:48277 CLOSE_WAIT 4444/java
tcp 1 0 ::ffff:127.0.0.1:8080 ::ffff:127.0.0.1:48273 CLOSE_WAIT 4444/java
tcp 1 0 ::ffff:127.0.0.1:8080 ::ffff:127.0.0.1:48272 CLOSE_WAIT 4444/java
tcp 1 0 ::ffff:127.0.0.1:8080 ::ffff:127.0.0.1:48268 CLOSE_WAIT 4444/java
tcp 1 0 ::ffff:127.0.0.1:8080 ::ffff:127.0.0.1:48267 CLOSE_WAIT 4444/java
tcp 1 0 ::ffff:127.0.0.1:8080 ::ffff:127.0.0.1:48266 CLOSE_WAIT 4444/java
tcp 1 0 ::ffff:127.0.0.1:8080 ::ffff:127.0.0.1:48264 CLOSE_WAIT 4444/java
tcp 1 0 ::ffff:127.0.0.1:8080 ::ffff:127.0.0.1:48263 CLOSE_WAIT 4444/java
tcp 1 0 ::ffff:127.0.0.1:8080 ::ffff:127.0.0.1:48258 CLOSE_WAIT 4444/java
tcp 1 0 ::ffff:127.0.0.1:8080 ::ffff:127.0.0.1:48308 CLOSE_WAIT 4444/java
隔上一天左右就成這樣了,然後網站就訪問不了了,看tomcat的catalina.out也沒什麼異常,誰給個提示:lol:
《解決方案》
程序有沒有可能呢
《解決方案》
回復 #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-li/article?mid=1394&prev=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 才會生效
# /etc/rc.d/init.d/network restart
**********************************************************************************
PS: 發生CLOSE_WAIT 的原因,可能在於程式內 一端的Socket使用close後,另一端的Socket沒有使用close.檢查一下代碼內是否有 Server端在某些異常情況時,沒有關閉Socket,將之修改,應可改正此一問題
《解決方案》
回復 #2 gamester88 的帖子 回復 #3 ziggler 的帖子
查不出來問題,程序員不認啊
~~~~~~~~~~~~~~~~~~~~~~~~~~
這個看過了,不行的
《解決方案》
回復 #4 gilet 的帖子
感覺應該是程序的問題。
找程序員的頭,查一下啊。