Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to handle CLOSE_WAIT

Status
Not open for further replies.

byk

Programmer
Jul 18, 2002
23
0
0
GB
Hi,

We have a client-server based application comunicating over sockets. Dropping the connection from client side is forcing the server-child-process to a CLOSE_WAIT (netstat) state.
Please suggest how to get rid of this and close the server-child-process.

Regards,
byk
 
Normally, a TCP session is concluded with a brief message exchange (much like the 3-way handshake):
Code:
System A       System B
--------       --------
 FIN     ---->
         <----  FIN/ACK
 ACK     ---->
CLOSE_WAIT occurs when the remote system does not finish the hang-up process:
Code:
System A       System B
--------       --------
 FIN     ---->
         <----  FIN/ACK
        (NO ACK)
In this case, system B will resend the FIN/ACK a few times before timing out. The state of the socket from System B's perspective is CLOSE_WAIT until System A either acknowledges the FIN/ACK, or System B times out (gives up).

CLOSE_WAIT is a normal state for a socket, but if everything goes smoothly this state is short-lived. CLOSE_WAIT is not cause for alarm, and can be safely ignored.

What can you do about CLOSE_WAIT when the remote system does not finish the hang-up? Not much, other than wait for the connection to time-out.


Best of luck,
Jason Deckard
 
The server socket is not timing out even after 2 hours.

Is there any way of getting the pid of the process which holds the CLOSE-WAIT socket (either through ps or netstat etc) ? If so that the process-id can be killed by a monitor process.

Please advise.

Regards,
byk
 
I agree that two hours is excessive.

Although the operating system controls how long the socket will remain in CLOSE_WAIT, you can find out which process is controlling the port with lsof (the source is at ftp://vic.cc.purdue.edu/pub/tools/unix/lsof/):

Code:
lsof -i | grep (port number)
 
It seems that &quot;lsof&quot; is not a standard HP-UX command.
Moreover in this case I have multiple child processes listening over the same socket port.
How to determine the pid of the process that has actually
reached CLOSE_WAIT

By the way .. thanks for the replies Jason.

Regards,
byk
 
Hi,

Please suggest me the syntax for using a setsockopt in C over HP-UX. What exaxtly are the parameters 4,5 in setsockopt?
int setsockopt(int s,int level, int optname, const void* optval, int optlen);

I actually need to try SO_KEEPALIVE to solve the problem mentioned.

Regards,
byk
 
Parameter four is the value of the setting (for the option named in paramter three). Parameter five is the length, in bytes, of the value provided in parameter four:

Code:
  int trueval = 1;
  rval = setsockopt( sockid, SOL_SOCKET, SO_KEEPALIVE, &truval, sizeof(trueval) );

I'm curious to find out if setting the keep-alive solves your problem. I would be suprised if your OS attempts to send a keep-alive packet from a socket that is not in the CONNECTED state.

Good luck,
Jason
 
We have used the command :

ndd -set /dev/tcp tcp_discon_by_addr
&quot;0a0a04081f42 a0a8c2f0527&quot;

Where :

local ip=10.10.4.8 = 0x0a0a0408
local port=8002 = 0x1f42

remote ip = 10.10.140.47 = 0x0a0a8c2f
remote port = 1319 = 0x0527


Roger Bosley
Capital Blue Cross
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top