Reviving an old code review [1], after further investigation…

Pertinent details from previous review:
"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.

The native socket returned by ServerSocket.accept() should be configured 
so it will not be inherited by a child process, 
SetHandleInformation(<HANDLE>, HANDLE_FLAG_INHERIT, FALSE)."
http://cr.openjdk.java.net/~chegar/8067105/webrev.00/webrev/

—

There were on objections to the changes, since they are mainly benign, but I 
took the action to investigate why we are calling CreateProcess with 
bInheritHandles set to TRUE. It appears that, without major work, we cannot 
change this.

From 7147084 [2]:

Java does not provide the API to change inherit-bit for any handle. More over, 
since at least the JDK 6, it is assumed that all Java-created handles have no 
installed inherit-bit . The only handles that change the inherit-bit to 1 in 
the Java call are the handles of redirected Input, Output, and Error streams 
(IOE streams for short) for child process. That is the way these redirect the 
streams work. That's why we can not give up the nomination in [TRUE] the 
parameter [bInheritHandles] in the [CreateProcess] call. And I want to mention 
again that this is the only place in JDK where Java installs the inherit-bit. 
Java itself does not use handle inheritance.
—

Ivan pointed out that HANDLE_FLAG_INHERIT will not always work, in the case of 
Layered Service Providers, see [3], but it will work in the standard case.

Finally, I think that we will need to revisit the process creation 
implementation at some point, to see if bInheritHandles can be set to FALSE, 
but that is a larger, more significant, piece of work, that should be done 
separately.

-Chris.

P.S. if there are no objections to the changes I will amend an existing test 
case to cover these new cases.

[1] http://mail.openjdk.java.net/pipermail/net-dev/2014-December/008789.html
[2] 
https://bugs.openjdk.java.net/browse/JDK-7147084?focusedCommentId=13322689&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-13322689
[3] 
http://stackoverflow.com/questions/12058911/can-tcp-socket-handles-be-set-not-inheritable

Reply via email to