[英]Netty socket generate Close_wait status
我的應用程序Java在服務器中運行,打開端口並通過套接字與設備建立連接。 一切運行到一定程度,即使我的應用程序對收到的數據包完成了處理,很多連接仍停留在CLOSE_WAIT中。
我的意思是,CPU開始使用雙重資源,打開的文件在增加,並且CLOSE_WAIT狀態的數量也在增加。
在wireshark中,發送的數據包保持CLOSE_WAIT狀態,我們看到服務器沒有將FIN發送給客戶端。
PS:我在ubuntu 14.04信任服務器上,我在使用Netty 3.10.1
這是我制作管道的代碼:
@Override
public ChannelPipeline getPipeline() {
ChannelPipeline pipeline = Channels.pipeline();
if (resetDelay != null) {
pipeline.addLast("idleHandler", new IdleStateHandler(GlobalTimer.getTimer(), resetDelay, 0, 0));
}
pipeline.addLast("openHandler", new OpenChannelHandler(server));
if (loggerEnabled) {
pipeline.addLast("logger", new StandardLoggingHandler());
}
addSpecificHandlers(pipeline);
if (filterHandler != null) {
pipeline.addLast("filter", filterHandler);
}
if (reinitializeHandler != null) {
pipeline.addLast("reinitialize", reinitializeHandler);
}
if (refineHandler != null) {
pipeline.addLast("refine", refineHandler);
}
if (noFilterHandler != null) {
pipeline.addLast("nofilter", noFilterHandler);
}
if (specificFilterHandler != null) {
pipeline.addLast("specificfilter", specificFilterHandler);
}
if (reverseGeocoder != null) {
pipeline.addLast("geocoder", new ReverseGeocoderHandler(reverseGeocoder, processInvalidPositions));
}
pipeline.addLast("handler", new TrackerEventHandler(dataManager));
return pipeline;
}
CLOSE_WAIT表示您的程序仍在運行,並且尚未關閉套接字(內核正在等待它關閉)。 將-p添加到netstat中以獲取該pid,然后更加有力地將其殺死(如果需要,可以使用SIGKILL)。 那應該擺脫您的CLOSE_WAIT套接字。 您也可以使用ps查找pid。
SO_REUSEADDR用於服務器和TIME_WAIT套接字,因此不適用於此處。
請參閱此線程以獲取其他響應。
檢查您的應用程序代碼,以檢查在處理完客戶端會話后是否在所有創建的套接字上顯式調用close。
您的應用程序由於無法關閉套接字而泄漏了套接字。 所以關閉它們。 他們全部。 在最后塊。 當您讀取流的末尾或在套接字上獲取任何IOException
操作時。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.