Description
Follow-up to #1720 (fixed by microsoft/java-debug#645).
Since 0.60.2026102705, the first Stop sends terminate, keeps JDI attached, and the JVM shuts down gracefully, so breakpoints in shutdown hooks are hit. This works with "console": "internalConsole". With "console": "integratedTerminal" or "externalTerminal" the problem from #1720 is still there: shutdown hooks do not run at all.
Environment
- Operating System: Linux Mint 22.1
- JDK version: 21.0.7
- Java Debugger extension version: 0.60.2026102705 or later
Steps To Reproduce
- Use the program from Stop detaches the debugger before shutdown hooks run, so JVM shutdown cannot be debugged #1720:
public class App { public static void main(String[] args) throws Exception { Runtime.getRuntime().addShutdownHook(new Thread(() -> { System.out.println("hook start"); // breakpoint here System.out.println("hook end"); })); Thread.sleep(Long.MAX_VALUE); } }
- Launch it with
"console": "integratedTerminal"(or"externalTerminal"). - Set a breakpoint on the
hook startline. - Press Stop.
Current Result
The JVM is killed: the breakpoint is not hit and hook start is not printed in the terminal.
Expected Result
The same as with internalConsole: the JVM gets SIGTERM, the debugger stays attached, the shutdown-hook breakpoint is hit, and the session ends when the JVM exits.
Additional Informations
TerminateRequestHandler calls debugSession.terminate(), and DebugSession.terminate() does:
if (vm.process() != null && vm.process().isAlive()) {
vm.process().destroy();
} else if (vm.process() == null || vm.process().isAlive()) {
vm.exit(0);
}In terminal mode the debuggee is started through runInTerminal and connects to a ListeningConnector, so vm.process() is null and the code falls back to vm.exit(0). JDWP VirtualMachine.Exit ends the JVM without running shutdown hooks.
DebuggeeProcessHelper.terminate() can already destroy the process by context.getProcessId(), but it is only used when there is no debug session (noDebug). Even there it does not point to the JVM: VS Code's runInTerminal response gives the PID of the terminal shell, not of the debuggee.
Activity
issuelens commentedon Nov 12, 2026
Thanks for the detailed follow-up and reproduction. The current Java debug-server path supports the analysis:
TerminateRequestHandlerdelegates toDebugSession.terminate(), which usesvm.exit(0)when JDI has no associatedProcess. That leaves terminal-launched sessions on a different termination path frominternalConsole, so this is a valid remaining bug rather than a duplicate of #1720; #1720 is the related fix that exposed this terminal-specific gap.As a workaround, focus the integrated/external terminal and send Ctrl+C instead of using Stop so the JVM can handle the signal and run its shutdown hooks.
Sachin-nsk commentedon Nov 30, 2026
Hi, I'd like to work on this.
When the app runs in a terminal, the debugger has no handle to the Java process. So Stop ends the JVM without running shutdown hooks.
My idea is to find the Java process by the debug address on its command line, and ask it to exit normally (SIGTERM). This should work on Linux and macOS. Windows would stay as it is now.
I'll test it and open a PR . Please tell me if you prefer a different approach