Windows handles can be set as inherited or not, to control whether child processes will receive them (when bInheritHandles in CreateProcess is TRUE). However, using SetHandleInformation to indicate an unsecured SOCKET does not always work. In particular, when certain layered service providers (LSPs) are installed, the child process inherits the handle anyway. This, in particular, can cause bugs with listening sockets. (But due to another problem , if a child tried to use a socket, he will not be able to! Real catch-22!)
Steps to play
- Create, for example, a listening jack. Mark it non inheritable using
SetHandleInformation . - Save the child,
bInheritHandles true. - Close the socket in the parent and try to bind it to the port again.
If LSP (not IFS) is installed, for example. PCTools Internet Security, the listening socket will be open in the child (apparently in netstat ), although SetHandleInformation is called on the socket to disable inheritance before creating the child.
For an alternative scenario, see the (brief) steps in KB2398202 .
What are some workarounds?
Nicholas wilson
source share