void (@NotNull ProcessEvent event, boolean willBeDestroyed) { ProcessHandler processHandler = event.getProcessHandler(); final DebugProcessImpl debugProcess = getDebugProcess(processHandler); if (debugProcess != null) { // if current thread is a "debugger manager thread", stop will execute synchronously // it is KillableColoredProcessHandler responsibility to terminate VM debugProcess.stop(willBeDestroyed && !(processHandler instanceof KillableColoredProcessHandler && ((KillableColoredProcessHandler)processHandler).shouldKillProcessSoftly())); // wait at most 10 seconds: the problem is that debugProcess.stop() can hang if there are troubles in the debuggee // if processWillTerminate() is called from AWT thread debugProcess.waitFor() will block it and the whole app will hang if (!DebuggerManagerThreadImpl.isManagerThread()) { if (SwingUtilities.isEventDispatchThread()) { ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> { ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); indicator.setIndeterminate(false); int wait = 0; while (wait < WAIT_KILL_TIMEOUT && !indicator.isCanceled()) { indicator.setFraction((double)wait / WAIT_KILL_TIMEOUT); debugProcess.waitFor(200); wait += 200; } }, JavaDebuggerBundle.message("waiting.for.debugger.response"), true, debugProcess.getProject()); } else { debugProcess.waitFor(WAIT_KILL_TIMEOUT); } } } }