RFR 8067105: Socket returned by ServerSocket.accept() is inherited by child process on Windows

Chris Hegarty chris.hegarty at oracle.com
Thu Dec 18 11:52:48 UTC 2014


Thanks for looking at this Alan.

Surprisingly this issue has existed for a long time. I tested with the FCS version of JRE 5, 6, 7, 8, and 9-ea, on Windows Server 2008 R2, and 2012, and the newly accepted socket inherit behaviour can be seen.  NIO server socket channels also suffers from the same problem. 

Since networking and NIO already sets HANDLE_FLAG_INHERIT on newly created sockets, I’d like to keep it consistent, and set it on accepted sockets too. I also think that this fix should be backpored to previous releases, so a small localised change seems appropriate.

Complete and updated webrev:
   http://cr.openjdk.java.net/~chegar/8067105/webrev.00/webrev/

I will file a separate bug to investigate why CreateProcess is being called with bInheritHandles set to TRUE, as I think any changes here will have a wider impact.

-Chris.

On 17 Dec 2014, at 22:12, Alan Bateman <Alan.Bateman at oracle.com> wrote:

> On 17/12/2014 15:47, Chris Hegarty wrote:
>> A socket connection which is returned by ServerSocket.accept() is inherited by a child process. The expected behavior is that the socket connection is not inherited by the child process. This is an oversight in the original implementation, that only sets HANDLE_FLAG_INHERIT for newly created sockets.
>> 
> I assume the real issue here is that CreateProcess is being called with bInheritHandles set to TRUE, I think we might have to dig into the reasons for that as I'm sure it has been looked at many times. There is also code in the Process implementation to toggle the inheritance setting prior to calling CreateProcess and I'm also curious why that isn't working.
> 
> So while you proposed change is benign, I think there may be more going on here that we should look into.
> 
> -Alan.



More information about the net-dev mailing list