JDK-6598160 : Windows IPv6 Socket implementation doesn't set the handle to not inherit
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 5.0,6
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_2003,windows_xp
  • CPU: x86
  • Submitted: 2007-08-28
  • Updated: 2010-04-02
  • Resolved: 2007-09-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other JDK 6 JDK 7
5.0u17-revFixed 6u10Fixed 7 b21Fixed
Description
See http://forums.java.net/jive/thread.jspa?threadID=29654&tstart=0

You can reproduce this issue running on Windows XP or 2003 with IPv6 enabled.

--- begin code ---
public class SockTest
{
    public static void main(String[] args) throws Exception {
        ServerSocket ss = new ServerSocket(4444);
        Runtime.getRuntime().exec(new String[] {"notepad.exe"});
        ss.close();
    }
}
--- end code ---

The above testcase spawns a notepad. Notepad inherits the handle to the socket, so if you try and re-execute the test if fails with "BindException: Address already in use".

This is reproducible with Java SE 5, 6, and 7.

Comments
SUGGESTED FIX This seems to be the correct file for the change mentioned : /j2se/src/windows/native/java/net/PlainSocketImpl.c
24-11-2008

WORK AROUND This problem should not effect OpenJDK 7 b15 (or greater) on Windows Vista. OpenJDK 7 is using the new TCP/IP stack on Vista and already sets HANDLE_FLAG_INHERIT FALSE for the dual stack socket.
31-08-2007

SUGGESTED FIX ------- TwoStacksPlainSocketImpl.c ------- 170a171,172 > /* Set socket attribute so it is not passed to any child process */ > SetHandleInformation((HANDLE)(UINT_PTR)fd1, HANDLE_FLAG_INHERIT, FALSE);
31-08-2007

EVALUATION The windows native implementation for socketCreate needs to set HANDLE_FLAG_INHERIT FALSE for the socket on the IPv6 stack.
28-08-2007

WORK AROUND run with the command line property set: -Djava.net.preferIPv4Stack=true
28-08-2007