Fixing connection refused with JMX port issue after gradle 7.3.x upgrade

Fixing connection refused with JMX port issue after gradle 7.3.x upgrade

Recently we upgraded our project to Gradle 7.3. Application worked locally passing all tests so we deployed version to testing env for getting heap snapshots. We port-forwarded to application pod and tried connecting to JMX port through visual VM. To our surprise, JMX connection got refused. Since there was no change in Kubernetes configs and it was working before, we reviewed the changes in PR and didn't find any suspects. After going through Gradle docs, we found some changes happened in version 7.2 related to environment variables. Suspecting this, we added a query on stack overflow to seek help.

Stack overflow post : https://stackoverflow.com/questions/78780159/unable-to-connect-visualvm-to-java-application-after-7-3-gradle-upgrade

We continued debugging it while we hoped to get answer to this from dev community. Below are the list of JVM parameters passed in build file

ext.getJvmArgs = { jmxPort, jdwpPort, initialRamPge = 50.0, maxRamPge = 70.0 ->
    return ["-XX:InitialRAMPercentage=$initialRamPercentage",
            "-XX:MaxRAMPercentage=$maxRamPercentage",
            "-XX:+UseStringDeduplication",
            "-XX:+UseG1GC",
            "-Duser.timezone=\"UTC\"",
            "-Dcom.sun.management.jmxremote",
            "-Dcom.sun.management.jmxremote.authenticate=false",
            "-Dcom.sun.management.jmxremote.ssl=false",
            "-Dcom.sun.management.jmxremote.local.only=false",
            "-Dcom.sun.management.jmxremote.port=$jmxPort",
            "-Dcom.sun.management.jmxremote.rmi.port=$jmxPort"]
}

application {
    applicationDefaultJvmArgs = project.getJvmArgs(3212, 3214, 65, 95)
    getMainClass().set('com.xxx.yyy.AbcMain')
}

        

Below snapshot is taken from Visual VM snapshot from Gradle 6.1 with "-Duser.timezone=\"UTC\"" . We can see all parameters present in JVM arguments

with Gradle 7.1.x

We took Visual VM snapshot again with Gradle 7.3.3 with "-Duser.timezone=\"UTC\"". As shown below in snapshot, all parameters after problematic parameter are truncated. Also we observed that profiling options are disabled.

with Gradle 7.3.x

Local debugging showed that all parameters including user.timezone were absent from JVM parameters list. I observed that that it was an issue with JvmOptions parameter containing double quotes which previous version of Gradle seem to ignore or parse correctly.

Simple change from "-Duser.timezone=\"UTC\"" to "-Duser.timezone=UTC" fixed the issue and all parameters started showing up

We tried visual VM again after removing extra double quotes around time zone parameter and all parameters which were missing appeared again and profiling options got enabled.


with Gradle 7.3.x

I am still trying to understand change sin Gradle 2 about expanding parameters restriction but it seems that wasn't the reason here we suspected.

Hope this helps someone who might be facing this issue migrating from old version of Gradle.

Happy Learning ! Cheers !

要查看或添加评论,请登录

Surinder Kumar Mehra的更多文章

社区洞察

其他会员也浏览了