Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8167337

When jmxremote.port=0, JDP broadcasts "0" instead of assigned port

XMLWordPrintable

        FULL PRODUCT VERSION :
        java version "1.8.0_91"
        Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
        Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

        ADDITIONAL OS VERSION INFORMATION :
        Linux hc02 3.13.0-86-generic #131-Ubuntu SMP Thu May 12 23:33:13 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

        Darwin lmp-jwalnes02 14.5.0 Darwin Kernel Version 14.5.0: Mon Jan 11 18:48:35 PST 2016; root:xnu-2782.50.2~1/RELEASE_X86_64 x86_64

        A DESCRIPTION OF THE PROBLEM :
        Specifying "com.sun.management.jmxremote.port=0", will force JMX to auto assign a free port to listen on (typically relying on the underlying OS's ephemeral port range).

        This works as expected, a port is assigned dynamically. According to the source, port=0 is a valid value: http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/src/share/classes/sun/management/jmxremote/ConnectorBootstrap.java#l327

        However, if I use port=0 in conjunction with JDP, the port number contained in the JDP multicast packet is 0. This, of course, will not work when attempting to connect from Java Mission Control and other tools.

        I believe the correct behavior is for JDP to broadcast the port the remote agent is bound to, rather than the contents of the JVM property.
        The actual port can be determined like this: http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/src/share/classes/sun/management/jmxremote/ConnectorBootstrap.java#l791


        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run a Java process with JVM properties:

        On another machine, which is on the same network, ppen Java Mission Control. The named process should appear. Connect to this and open MBean Browser or Flight Recorder (doesn't matter which).

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Expect to open a live MBean Browser or Flight Recorder on the remote process.
        ACTUAL -
        Fails to connect to port "0" of remote process.

        REPRODUCIBILITY :
        This bug can be reproduced always.

        CUSTOMER SUBMITTED WORKAROUND :
        I have worked around this temporarily by disabling JDP at the agent level and instead programmatically calling it myself.

        This involves:

        1. Start JVM with jmxremote.port=0

        2. Calling sun.management.ConnectorAddressLink.importRemoteFrom(0).get("sun.management.JMXConnectorServer.0.remoteAddress") to obtain the rmi service uri

        3. Parsing the uri to obtain the bound port

        4. Manually calling sun.management.jdp.JdpController.startDiscoveryService() with the correct port

        This works. But I would prefer to not have to do this as it reaches into the internals of sun.management, and it is additional code that needs to be maintained in 'user space'.

              asapre Amit Sapre
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Created:
                Updated:
                Resolved: