Skip to content

Commit 3adbc03

Browse files
authored
Handle VM disconnection gracefully and reorder termination logic (#626)
* Ignore VMDisconnected on detach; reorder terminate Wrap vm.dispose() in a try/catch to ignore VMDisconnectedException when the VM has already disconnected (e.g. process terminated) to avoid spurious errors during detach. Reorder calls in DisconnectRequestHandler to invoke terminate() before detach() when terminateDebuggee is true and the session is not attached, ensuring the debuggee is terminated prior to detaching. * Always detach debug session on terminate Wrap debugSession.terminate() in a try/finally so debugSession.detach() is always invoked when terminateDebuggee is true and the session is not attached. This ensures the session is detached even if terminate() throws, avoiding potential dangling sessions. Other detach logic is unchanged.
1 parent ae2847e commit 3adbc03

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/DebugSession.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,11 @@ public void resume() {
117117

118118
@Override
119119
public void detach() {
120-
vm.dispose();
120+
try {
121+
vm.dispose();
122+
} catch (VMDisconnectedException ex) {
123+
// ignore — VM already disconnected (e.g. process was terminated first)
124+
}
121125
}
122126

123127
@Override

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/DisconnectRequestHandler.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ public void destroyDebugSession(Command command, Arguments arguments, Response r
2626
IDebugSession debugSession = context.getDebugSession();
2727
if (debugSession != null) {
2828
if (disconnectArguments.terminateDebuggee && !context.isAttached()) {
29-
debugSession.detach();
30-
debugSession.terminate();
29+
try {
30+
debugSession.terminate();
31+
} finally {
32+
debugSession.detach();
33+
}
3134
} else {
3235
debugSession.detach();
3336
}

0 commit comments

Comments
 (0)