coherence-community / oracle-bedrock

Oracle Bedrock
Other
55 stars 31 forks source link

RemoteDebugging Option may incorrectly choose an IPv6 address when IPv4 is selected #337

Closed brianoliver closed 8 years ago

brianoliver commented 8 years ago

Occasionally we've seen the following error message when attempting to launch a JavaApplication with RemoteDebugging enabled (or automatically detected).

[storage-1:err:10455]    1: ERROR: transport error 202: gethostbyname: unknown host
[storage-1:out:10455]    1: FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197)
[storage-1:err:10455]    2: ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
[storage-1:err:10455]    3: JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [debugInit.c:750]
[storage-1:out:10455]    2: (terminated)
[storage-1:err:10455]    4: (terminated)

When this occurs, the Java Options look something like:

Java Options            : -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=fe80:0:0:0:0:0:0:1%lo0:30002

Even though IPv4 is chosen:

System Properties       : bedrock.runtime.orphanable                   false
                        : bedrock.runtime.parent                       //127.0.0.1:61993
                        : com.oracle.common.io.BufferManagers.checked  true
                        : java.awt.headless                            true
                        : java.net.preferIPv4Stack                     true

It appears that the InetAddress chosen from the AvailablePortIterator in the RemoteDebugging.TransportAddress constructor:

        public TransportAddress(AvailablePortIterator ports)
        {
            this(ports.getInetAddresses().iterator().next(), new Capture<>(ports));
        }

picks the first InetAddress, which may be an IPv6 address. Instead we need to carefully filter the addresses to ensure that we're choosing an appropriate type, like we do when launching the server-sockets.

brianoliver commented 8 years ago

According to the transports available for remote debugging (http://docs.oracle.com/javase/8/docs/technotes/guides/jpda/conninv.html#Transports), only IPv4 is supported.

Hence we need to ensure that only an IPv4 InetAddress is chosen for RemoteDebugging.TransportAddresses