java-11rmijmxjstatd

Could not bind /JStatRemoteHost to RMI Registry


I am running a Java 11 app inside docker container on my machine and trying to connect it via VisualVM.

I have already added required JMX parameters in CMD instruction of my Dockerfile

-Dcom.sun.management.jmxremote 
-Dcom.sun.management.jmxremote.port=1099 
-Dcom.sun.management.jmxremote.local.only=false 
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false

Inside the container when I am trying to run the jstatd, getting below error:

/ # jstatd -J-Djava.rmi.server.logCalls=true -J-Djava.net.preferIPv4Stack=true -J-Djava.security.policy=jstatd.policy
Could not bind /JStatRemoteHost to RMI Registry
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
        java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
        java.io.InvalidClassException: filter status: REJECTED
        at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
        at java.rmi/sun.rmi.transport.Transport$1.run(Unknown Source)
        at java.rmi/sun.rmi.transport.Transport$1.run(Unknown Source)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at java.rmi/sun.rmi.transport.Transport.serviceCall(Unknown Source)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(Unknown Source)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.base/java.lang.Thread.run(Unknown Source)
        at java.rmi/sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:303)
        at java.rmi/sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:279)
        at java.rmi/sun.rmi.server.UnicastRef.invoke(UnicastRef.java:380)
        at java.rmi/sun.rmi.registry.RegistryImpl_Stub.rebind(RegistryImpl_Stub.java:158)
        at java.rmi/java.rmi.Naming.rebind(Naming.java:177)
        at jdk.jstatd/sun.tools.jstatd.Jstatd.bind(Jstatd.java:59)
        at jdk.jstatd/sun.tools.jstatd.Jstatd.main(Jstatd.java:145)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
        java.io.InvalidClassException: filter status: REJECTED
        at java.rmi/sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
        at java.rmi/sun.rmi.server.UnicastServerRef.oldDispatch(Unknown Source)
        at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
        at java.rmi/sun.rmi.transport.Transport$1.run(Unknown Source)
        at java.rmi/sun.rmi.transport.Transport$1.run(Unknown Source)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at java.rmi/sun.rmi.transport.Transport.serviceCall(Unknown Source)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(Unknown Source)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.io.InvalidClassException: filter status: REJECTED
        at java.base/java.io.ObjectInputStream.filterCheck(Unknown Source)
        at java.base/java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
        at java.base/java.io.ObjectInputStream.readClassDesc(Unknown Source)

Policy file is looking like this:

/ # cat jstatd.policy 
grant codebase "jrt:/jdk.jstatd" {permission java.security.AllPermission;}; 
grant codebase "jrt:/jdk.internal.jvmstat" {permission java.security.AllPermission;};

Please suggest if I am missing something here.

Thanks


Solution

  • There's no need to run jstatd with policy. After adding below additional jvm args, I was able to connect jmx client to application.

    -Djava.rmi.server.hostname=127.0.0.1 -Dcom.sun.management.jmxremote.rmi.port=1099
    

    So overall argument should be like this:

    -Dcom.sun.management.jmxremote 
    -Dcom.sun.management.jmxremote.port=1099 
    -Dcom.sun.management.jmxremote.local.only=false 
    -Dcom.sun.management.jmxremote.ssl=false
    -Dcom.sun.management.jmxremote.authenticate=false
    -Djava.rmi.server.hostname=127.0.0.1
    -Dcom.sun.management.jmxremote.rmi.port=1099