The following reply was made to PR general/3401; it has been noted by GNATS.

From: Frank Jas <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: Re: general/3401: no shutdown() of client socket in ap_bclose()
Date: Fri, 20 Nov 1998 13:22:15 -0800 (PST)

 Thanks for the quick reply, sorry about my delay in replying to you.
 In general, I have observed TCP connections going into a TIME-WAIT state
 on the NeXT operating system and at least upto Sunos 5.4 (i.e. Solaris 2.4)
 if a socket was closed before a shutdown() was performed.
 
 The behaviour I saw with Apache
 was I would read from the connection to the server until EOF,
 and under certain (seemingly unrelated) circumstances the
 close() wouldn't terminate the connection properly.
 Running in the debugger, I was able
 to stop the behavior by calling shutdown() from the debugger
 prompt just before the call to close() in ap_pclosef().
 
 When I began programming with sockets I was surprised to observe
 that close() without a shutdown() could leave the socket
 in a TIME-WAIT state until it timed out on its own.  I also
 noticed that terminating a process with an active TCP socket could
 leave the socket in the same state.  You would think the kernel
 would cleanup the socket table and do the proper handshaking to
 close the connection, but that is not what I have observed.
 Perhaps my perspective is a holdover from UNIX OSes of 5-10 years ago, where 
the
 TIME-WAIT behavior was quite common, but Solaris 2.4 still
 exhibits that behavior.
 
 Whether shutdown() is required is not discussed in the 'man' pages,
 nor in text's on UNIX network programming.
 
 As far as Apache is concerned, since the NeXT platform is dead, changing
 the source on that account is fairly pointless.  On the other hand,
 since the BUFF structure appears to keep track of whether the 'fd'
 is a socket or not, adding shutdown() before close() in that case
 is possible and is not incorrect.  Unfortunately, ap_pclosef() works
 with alarms blocked(), so simply adding a shutdown() in ap_bclose()
 may not be possible.  Changing the call inside ap_bclose() to
 ap_pclosesocket() in the case when it is a socket won't have any affect unless
 closesocket() is also changed to include a shutdown() call.
 
 In order to make the change, you could move the #ifdef on buff.c, line 1405
 down to between 1414 and 1415, so non WIN32 platforms would
 also call ap_pclosesocket(), and then reimplement closesocket() 
 as follows:
 
 src/include/ap_config.h: 930
 
 #define closesocket(s)         (shutdown (s, 2), close (s))
 
 This way, you would be sure the other side of the connection wouldn't
 go into TIME-WAIT, rather than relying on the sometimes unpredicatable
 behavior UNIX OSes exhibit in this regard.
 
 No reply is necessary, and thanks for the effort in maintaining/improving
 this software.
 
 Frank Jas
 
 

Reply via email to