RHEL : How to deal with “CLOSE_WAIT” and “TIME_WAIT” connection

RHEL : How to deal with “CLOSE_WAIT” and “TIME_WAIT” connection

 
Linux How to Document

CLOSE_WAIT is the state for the TCP connection after the remote side has requested a shut down(FIN), and the TCP connection is waiting for the local application to close the socket. There is no timeout for a thread in CLOSE_WAIT state. So need to find out why the receiving application is not doing a proper close() call on the socket

 

 
 
 
 
For Example look at the following netstat output:
 
# netstat -a | grep dcd
      *.dcd               *.*                0      0     0      0 LISTEN
support.dcd         troppus.774           5840      0 10124      0 CLOSE_WAIT
support.dcd         troppus.638           5840      0 10124      0 CLOSE_WAIT
support.dcd         troppus.818           5840      0 10124      0 CLOSE_WAIT
support.dcd         troppus.782           5840      0 10124      0 CLOSE_WAIT
From the about output , you can see several connection are in CLOSE_WAIT  State.

 

Connection Flow for TCP Connection that leads to CLOSE_WAIT State

 

tcp_close_1
 

How do we Close the CLOSE_WAIT connections?

 
As of now , there is no reasonable way to clear these connections without doing network restart or server reboot.
 

::: What is TIME_WAIT Connection?

 
TIME-WAIT – represents waiting for enough time to pass to be sure the remote TCP received the acknowledgment of its connection termination request. The Connections enter into TIME_WAIT status only during the condition when too many clients connections are established in too short period of time and each clients disconnect the connection quickly
 
Red Hat Enterprise Linux set this value as 60 seconds in the code level. It’s not changeable, so we don’t have an option on the command line.
 

How do we Reduce the TIME_WAIT Sockets?

 
Below Two related parameter could help us to reduce TIME_WAIT sockets, but you have to you have to tune them only on expert advice who knows your environment better.
 
tcp_tw_recycle – BOOLEAN  – 
 Enable fast recycling TIME-WAIT sockets. Default value is 0. Enabling this option is not recommended since this causes problems when working with NAT(Network Address Translation).
tcp_tw_reuse – BOOLEAN
 Allow to reuse TIME-WAIT sockets for new connections when it is safe from protocol viewpoint. Default value is 0.
 

How do we activate it?

 Add following lines into /etc/sysctl.conf.
 
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
 
After adding that options, please execute the following command to apply the above changes.
 
#sysctl -p
5 (3)
Article Rating (3 Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
Jak znaleźć najszybszy publiczny serwer DNS w Polsce?
Viewed 2500 times since Mon, May 21, 2018
Find All Large Files On A Linux System
Viewed 2072 times since Mon, Oct 29, 2018
How To: Linux Hard Disk Encryption With LUKS [ cryptsetup Command ]
Viewed 7239 times since Fri, Jul 13, 2018
RHCS6: Create a new Logical Volume / Global Filesystem 2 (GFS2)
Viewed 2153 times since Sun, Jun 3, 2018
Linux – delete the LUN and remove traces from OS
Viewed 3452 times since Tue, May 22, 2018
18 Quick ‘lsof’ command examples for Linux Geeks
Viewed 11440 times since Sun, Jun 30, 2019
Linux Proxy Server Settings – Set Proxy For Command Line
Viewed 3291 times since Mon, Feb 18, 2019
Using renice and taskset to manage process priority and CPU affinity with Linux OEL 6.4
Viewed 3515 times since Mon, Feb 17, 2020
SYS: Configure a local repository. local repo
Viewed 10854 times since Mon, Oct 29, 2018
Increase A VMware Disk Size (VMDK) Formatted As Linux LVM without rebooting
Viewed 15279 times since Wed, May 30, 2018