Workaround patch for MS CLOSE_WAIT bug

Pierre A. Humblet
Mon Apr 15 08:09:00 GMT 2002

Corinna Vinschen wrote:

> Sorry if I'm dense but... shouldn't the new FD_SETCF functionality
> allow to do the "right thing" without adding the oldsocks variable
> at all?!?  You wrote about the disadvantage that the child inherits
> that array...

The oldsocks array is needed in the parent because the MS bug
precisely requires the last close() on a socket to be done by 
the parent, after all other processes referencing the socket 
are gone (*). 

It's true that the oldsocks array is not needed in the child.
Is there a way  to declare a variable "NO_COPY" in an application?
However the oldsocks array is just a an array of integers. The child
can't (and won't try anyway) make use of them because the underlying 
handles have not been duplicated. 

(*) My example code assumes that the child has not created detached 
processes that keep accessing the socket after the child has
exited (but exec() chains are OK). 
Is that the case for applications created by inetd & sshd? 
If this assumption is not true, then shutdown() can't be called 
in the parent and CLOSE_WAIT may still occur, albeit at a reduced 
frequency [probably]. 

More information about the Cygwin-patches mailing list