简体   繁体   English

Netty套接字生成Close_wait状态

[英]Netty socket generate Close_wait status

My application java, is running in server, openning port and made connection with devices by socket. 我的应用程序Java在服务器中运行,打开端口并通过套接字与设备建立连接。 Everythings went run till a certain point, lot of connection stay in CLOSE_WAIT, even if my application finish the process on the packet I receive. 一切运行到一定程度,即使我的应用程序对收到的数据包完成了处理,很多连接仍停留在CLOSE_WAIT中。

What I remark is that CPU began to use double ressource, open file are increasing, and number of CLOSE_WAIT status are increasing also. 我的意思是,CPU开始使用双重资源,打开的文件在增加,并且CLOSE_WAIT状态的数量也在增加。

In the wireshark, the packet sended which leave a CLOSE_WAIT status, we see that server didn't send FIN to the client. 在wireshark中,发送的数据包保持CLOSE_WAIT状态,我们看到服务器没有将FIN发送给客户端。

PS: I'm on ubuntu 14.04 trusty server, I'm using Netty 3.10.1 PS:我在ubuntu 14.04信任服务器上,我在使用Netty 3.10.1

Here is the code where I Made 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;
}

CLOSE_WAIT means your program is still running, and hasn't closed the socket (and the kernel is waiting for it to do so). CLOSE_WAIT表示您的程序仍在运行,并且尚未关闭套接字(内核正在等待它关闭)。 Add -p to netstat to get the pid, and then kill it more forcefully (with SIGKILL if needed). 将-p添加到netstat中以获取该pid,然后更加有力地将其杀死(如果需要,可以使用SIGKILL)。 That should get rid of your CLOSE_WAIT sockets. 那应该摆脱您的CLOSE_WAIT套接字。 You can also use ps to find the pid. 您也可以使用ps查找pid。

SO_REUSEADDR is for servers and TIME_WAIT sockets, so doesn't apply here. SO_REUSEADDR用于服务器和TIME_WAIT套接字,因此不适用于此处。

Refer to this thread for other responses. 请参阅此线程以获取其他响应。

Check your application code to check if you are explicitly calling close on all the sockets created once you are done handling the client session. 检查您的应用程序代码,以检查在处理完客户端会话后是否在所有创建的套接字上显式调用close。

Your application is leaking sockets by failing to close them. 您的应用程序由于无法关闭套接字而泄漏了套接字。 So close them. 所以关闭它们。 All of them. 他们全部。 In finally blocks. 在最后块。 When you read end of stream or get any IOException operatng on the socket. 当您读取流的末尾或在套接字上获取任何IOException操作时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM