{"record":{"id":"8c20e92427404496","repo":"JetBrains/intellij-community","slug":"attach-vm-failed","errorCode":null,"errorMessage":"ATTACH_VM_FAILED","messagePattern":"ATTACH_VM_FAILED","errorType":"exception","errorClass":"ExecutionException","httpStatus":null,"severity":"error","filePath":"java/execution/impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemTaskDebugRunner.java","lineNumber":128,"sourceCode":"    descriptor.setRunnerLayoutUi(runContentDescriptor.getRunnerLayoutUi());\n    return descriptor;\n  }\n\n  private static @NotNull XDebugProcess jvmProcessToDebug(\n    @NotNull XDebugSession session,\n    ExternalSystemRunnableState state,\n    @NotNull ExecutionEnvironment env\n  ) throws ExecutionException {\n    String debugPort = String.valueOf(state.getDebugPort());\n    RemoteConnection connection = state.isDebugServerProcess()\n                                  ? new RemoteConnection(true, \"127.0.0.1\", debugPort, true)\n                                  : new RemoteConnectionStub(true, \"127.0.0.1\", debugPort, true);\n    DebugEnvironment environment = new DefaultDebugEnvironment(env, state, connection, DebugEnvironment.LOCAL_START_TIMEOUT);\n\n    final DebuggerSession debuggerSession = DebuggerManagerEx.getInstanceEx(env.getProject()).attachVirtualMachine(environment);\n\n    if (debuggerSession == null) {\n      throw new ExecutionException(ATTACH_VM_FAILED);\n    }\n\n    final DebugProcessImpl debugProcess = debuggerSession.getProcess();\n\n\n    XDebugSessionImpl sessionImpl = (XDebugSessionImpl)session;\n    ExecutionResult executionResult = debugProcess.getExecutionResult();\n    sessionImpl.addExtraActions(executionResult.getActions());\n    if (executionResult instanceof DefaultExecutionResult) {\n      sessionImpl.addRestartActions(((DefaultExecutionResult)executionResult).getRestartActions());\n    }\n    return JavaDebugProcess.create(session, debuggerSession);\n  }\n\n  private static @Nullable RunContentDescriptor createProcessToDebug(\n    ExternalSystemRunnableState state,\n    @NotNull ExecutionEnvironment env\n  ) throws ExecutionException {","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/java/execution/impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemTaskDebugRunner.java#L110-L146","documentation":"ExternalSystemTaskDebugRunner attaches the IntelliJ debugger to a Gradle/Maven test JVM via DebuggerManagerEx.attachVirtualMachine with a RemoteConnection on the configured debug port (127.0.0.1:<debugPort>). attachVirtualMachine returns null when the attach fails (VM did not open the debug port, connection handshake failed, timeout of DebugEnvironment.LOCAL_START_TIMEOUT); the runner then throws ExecutionException with the raw 'ATTACH_VM_FAILED' text.","triggerScenarios":"Debugging an External System (Gradle/Maven) task: the child JVM either never started with the expected -agentlib:jdwp arguments, the debug port was taken/firewalled, the build finished before attach, or the handshake exceeded LOCAL_START_TIMEOUT.","commonSituations":"Gradle daemon reuse conflicts with debug ports; test JVM forked by Gradle with different JDWP args; firewall/antivirus blocking 127.0.0.1 loopback sockets; heavy builds exceeding attach timeout; running with a Gradle version that filters agent args; WSL2 loopback networking quirks.","solutions":["Stop all Gradle daemons (./gradlew --stop) and retry — stale daemons do not accept the new JDWP settings","Disable parallel/forked test execution temporarily (org.gradle.parallel=false, maxParallelForks=1) so exactly one JVM opens the port","Check firewall/antivirus allows loopback connections; on WSL2 ensure networking mode supports localhost forwarding","If builds are slow, increase attach timeout via Registry/debugger settings and try again","As a fallback, run the tests with the IDE's native JUnit runner (delegate build/run to IntelliJ in Gradle settings) instead of debugging through Gradle"],"exampleFix":"# before: gradle.properties has org.gradle.parallel=true + forkEvery tests\n# after:\norg.gradle.parallel=false\n# and in build.gradle: test { maxParallelForks = 1 }","handlingStrategy":"retry","validationCode":"// before attach: confirm the debug port is actually listening\ntry (Socket s = new Socket()) {\n  s.connect(new InetSocketAddress(\"127.0.0.1\", debugPort), 2000);\n} catch (IOException io) {\n  return error(\"Target JVM did not open debug port \" + debugPort);\n}","typeGuard":null,"tryCatchPattern":"DebuggerSession session = null;\nfor (int attempt = 0; attempt < 2 && session == null; attempt++) {\n  session = DebuggerManagerEx.getInstanceEx(project).attachVirtualMachine(env);\n}\nif (session == null) throw new ExecutionException(\"ATTACH_VM_FAILED\");","preventionTips":["Run ./gradlew --stop before external-system debug sessions to kill stale daemons","Limit test forking/parallelism when debugging Gradle test tasks","Ensure loopback sockets are permitted by firewall/antivirus (and WSL2 localhost forwarding is on)","For flaky slow builds, prefer delegating build/run to IntelliJ to bypass the attach path"],"tags":["gradle","external-system","debugger","jdwp","attach","network"],"backgroundTag":null,"analyzedSha":"be881553f2a76ac8b4ea53950d93f0de78295c19","analyzedAt":"2026-08-14T14:13:06.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}