我的应用程序java,运行在服务器上,打开端口,通过socket与设备连接。所有的东西都运行到某一点,很多连接都停留在CLOSE_WAIT中,即使我的应用程序完成了对我收到的数据包的处理。
我所说的是,CPU开始使用双资源,打开的文件越来越多,CLOSE_WAIT状态的数量也在增加。
在wireshark中,发送的数据包处于CLOSE_WAIT状态,我们看到服务器没有向客户端发送FIN。
PS:我使用的是ubuntu 14.04可信服务器,我使用的是Netty 3.10.1
下面是我制作Pipeline的代码:
@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;
}发布于 2016-03-04 00:55:45
CLOSE_WAIT意味着你的程序还在运行,并且还没有关闭套接字(内核正在等待它关闭)。将-p添加到netstat以获取pid,然后更有力地终止它(如果需要,可以使用SIGKILL )。这应该会去掉你的CLOSE_WAIT套接字。您还可以使用ps查找pid。
SO_REUSEADDR是用于服务器和TIME_WAIT套接字的,所以这里不适用。
有关其他响应,请参阅this thread。
检查您的应用程序代码,以检查您是否在处理完客户端会话后显式地调用了所有创建的套接字。
发布于 2016-03-04 18:31:57
您的应用程序由于未能关闭套接字而导致套接字泄漏。那就闭上吧。他们所有人。在最终块中。当你读取流的末尾或者获取套接字上的任何IOException操作时。
https://stackoverflow.com/questions/35777986
复制相似问题