com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded
Asked Answered
A

5

26

I get AttachNotSupportedException while running jmockit tests on linux (ubuntu 64bit). Java version is 1.7.0_51. This JDK is from Oracle. Tests are run using ant(that probably is not relevant)

See the stack trace.

[junit] 
[junit] java.lang.RuntimeException: com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded
[junit]     at mockit.internal.startup.JDK6AgentLoader.getVirtualMachineImplementationFromEmbeddedOnes(JDK6AgentLoader.java:89)
[junit]     at mockit.internal.startup.JDK6AgentLoader.loadAgent(JDK6AgentLoader.java:54)
[junit]     at mockit.internal.startup.AgentInitialization.initializeAccordingToJDKVersion(AgentInitialization.java:21)
[junit]     at mockit.internal.startup.Startup.initializeIfNeeded(Startup.java:136)
[junit]     at mockit.internal.startup.Startup.initializeIfPossible(Startup.java:169)
[junit]     at junit.framework.TestResult.<clinit>(TestResult.java:15)
[junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:356)
[junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:1165)
[junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:1016)
[junit] Caused by: com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded
[junit]     at sun.tools.attach.LinuxVirtualMachine.<init>(LinuxVirtualMachine.java:106)
[junit]     at mockit.internal.startup.JDK6AgentLoader.getVirtualMachineImplementationFromEmbeddedOnes(JDK6AgentLoader.java:79)
[junit]     ... 8 more
[junit] Exception in thread "main" java.lang.ExceptionInInitializerError
[junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:356)
[junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:1165)
[junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:1016)
[junit] Caused by: java.lang.RuntimeException: com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded
[junit]     at mockit.internal.startup.JDK6AgentLoader.getVirtualMachineImplementationFromEmbeddedOnes(JDK6AgentLoader.java:89)
[junit]     at mockit.internal.startup.JDK6AgentLoader.loadAgent(JDK6AgentLoader.java:54)
[junit]     at mockit.internal.startup.AgentInitialization.initializeAccordingToJDKVersion(AgentInitialization.java:21)
[junit]     at mockit.internal.startup.Startup.initializeIfNeeded(Startup.java:136)
[junit]     at mockit.internal.startup.Startup.initializeIfPossible(Startup.java:169)
[junit]     at junit.framework.TestResult.<clinit>(TestResult.java:15)
[junit]     ... 3 more
[junit] Caused by: com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded
[junit]     at sun.tools.attach.LinuxVirtualMachine.<init>(LinuxVirtualMachine.java:106)
[junit]     at mockit.internal.startup.JDK6AgentLoader.getVirtualMachineImplementationFromEmbeddedOnes(JDK6AgentLoader.java:79)
[junit]     ... 8 more
[junit] Running chs.caf.cap

It appears to be related to AttachNotSupportedException while running jMockit tests on IBM JRE. This however is on IBM jre.

Angevin answered 22/8, 2014 at 3:11 Comment(2)
There is a great answer: #26140682Waites
In my case it was due to launching jcmd with a different user from the one owning the running process. One of the cases described into https://mcmap.net/q/169525/-running-jmap-getting-unable-to-open-socket-fileAero
A
32

Work around for now.

Adding '-XX:+StartAttachListener' to jvm argument fixed the issue.

A similar issue is discussed here at https://code.google.com/p/jmockit/issues/detail?id=136 and http://mail.openjdk.java.net/pipermail/macosx-port-dev/2013-October/006098.html (which talks about a possible regression in jdk7 build)

Angevin answered 22/8, 2014 at 3:16 Comment(2)
Apparently, it's a bug in the Attach API implementation in this version of the Oracle JRE for Linux. It's likely already fixed in 1.7.0_60 and above.Convenance
This was actually still an issue for me in 1.8.0_131 on LinuxParrnell
J
59

I had the same issue while I was trying to dump threads using jcmd. I was getting same error message even though I was running jcmd under the root user.

You need to run jcmd <pid> Thread.print under the same user as java process has, otherwise your connections will be dropped. Java doesn't care if you are root or not.

So basically:

sudo -u <java_process_user> jcmd <pid> Thread.print
Joyjoya answered 24/7, 2018 at 21:11 Comment(3)
Thank you. This was exactly what I was looking for. However, with Thread.dump I get the following error java.lang.IllegalArgumentException: Unknown diagnostic command. I had to use Thread.print.Pritchard
+100 THANK YOU VERY MUCHRockie
still facing the issue on java 8 (1.8.0_192).Hirokohiroshi
A
32

Work around for now.

Adding '-XX:+StartAttachListener' to jvm argument fixed the issue.

A similar issue is discussed here at https://code.google.com/p/jmockit/issues/detail?id=136 and http://mail.openjdk.java.net/pipermail/macosx-port-dev/2013-October/006098.html (which talks about a possible regression in jdk7 build)

Angevin answered 22/8, 2014 at 3:16 Comment(2)
Apparently, it's a bug in the Attach API implementation in this version of the Oracle JRE for Linux. It's likely already fixed in 1.7.0_60 and above.Convenance
This was actually still an issue for me in 1.8.0_131 on LinuxParrnell
U
6

Like @bbarker, I got the same error but on JDK 1.8.0_161 using the Linux subsystem in Windows 10 ("Bash on Ubuntu on Windows"). Configuring the Surefire plugin with the JVM argument mentioned above fixed the issue for me as well:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.21.0</version>
        <configuration>
            <argLine>-XX:+StartAttachListener</argLine>
        </configuration>
    </plugin>

Running the tests from a "normal" Windows command prompt works without the above, though.

Usurious answered 7/3, 2018 at 6:59 Comment(0)
O
0

I also got a similar problem when tried to check for Thread Deadlock. You can also use the command jcmd <PID> Thread.print to print the thread dump on the console and check if the program has a deadlock. You can check my answer with steps on Deadlock detection in Java

Orlina answered 22/6, 2020 at 16:54 Comment(0)
G
0

I got similar issue, in my case, changing JDK vendor from OPENJ9 to OPENJDK resolved the issue.

Gangrel answered 22/4, 2021 at 8:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.