Skip to content
Advertisement

Java – AttachNotSupportedException: Unable to open socket file: HotSpot VM not loaded

When attempting to attach an agent jar file onto another process running in java, I have came across the exception:

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

I was running linux, with java Oracle JDK 8_101, however after answering this question I’ve realized the O.S does not matter for the cause of this problem.

Edit: Answer:

If you encounter this problem, the reason it occured for me is because I was launching a program from a different JVM, other than the default JVM specified for the system.

i.e)

Program A (The launcher), is running on JVM-1 (JDK_8_1 for example, or JDK_8_1/jdk/jre).

Program A (The launcher), creates a process with java -jar programB.jar

Program B (The target), is running on the system’s default JVM, JVM-2 (JDK_8_2 for example, or JDK_8_2/jre).

Program A (The launcher) CANNOT attatch to Program B (The target), because the JVM Program A (The launcher) is running on, does not match the JVM of which Program B (The target) is running on, thus throwing the com.sun.tools.attach.AttachNotSupportedException:

Advertisement

Answer

Common reasons for this problem:

  • Attach socket /tmp/.java_pid1234 has been removed (e.g. by a scheduled job that periodically cleans up /tmp).
  • Target JVM is started with -XX:+DisableAttachMechanism option.
  • Garbage Collection or other long VM operation (e.g. Heap Dump) is in progress.
  • JVM cannot reach safepoint within attach timeout. This happens rarely, and the problem is typically intermittent.
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement