From 72f286d619232acfcc1eb56e0599d50d62aba882 Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Thu, 19 Nov 2026 11:25:14 +0800 Subject: [PATCH] fix(debugger): don't wait forever for a killed program on Windows (#4407) Stopping a launch waits for the program to exit and kills it after 10 s. On Windows the wait had no end after the kill: while any process of the launch still looked alive, Stop stayed on "Waiting for the process to exit" and Kill Process could not end it. Like on Unix, the stop now gives up 5 s after the kill (termination is asynchronous there) and logs it. Fixes #4280 --- crates/ide-dap/src/session.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/crates/ide-dap/src/session.rs b/crates/ide-dap/src/session.rs index dbf7346aa..88550fde0 100644 --- a/crates/ide-dap/src/session.rs +++ b/crates/ide-dap/src/session.rs @@ -504,6 +504,9 @@ impl Session { /// How long Stop waits for a launched program to exit before reporting the session ended. pub(crate) const DEBUGGEE_EXIT_WAIT: Duration = Duration::from_secs(10); +/// How long a stop waits for a killed program to be gone (Windows ends processes asynchronously). +#[cfg(windows)] +const DEBUGGEE_KILL_WAIT: Duration = Duration::from_secs(5); pub(crate) async fn remember_debuggee(s: &Arc) { #[cfg(windows)] @@ -643,14 +646,24 @@ pub(crate) async fn wait_for_debuggee(s: &Arc, terminate: bool) { } #[cfg(windows)] { + use std::time::Instant; remember_debuggee(s).await; - let deadline = std::time::Instant::now() + DEBUGGEE_EXIT_WAIT; + let deadline = Instant::now() + DEBUGGEE_EXIT_WAIT; + let mut killed: Option = None; // The captured tree is the oracle when it was captured; otherwise the job (every // process the launch started) is, so a failed capture can no longer end the wait // while the program still holds its port. while launch_running(s) { - if s.stop_force.swap(false, Ordering::AcqRel) || std::time::Instant::now() >= deadline { + let now = Instant::now(); + if s.stop_force.swap(false, Ordering::AcqRel) || (killed.is_none() && now >= deadline) { signal_debuggee(s, true).await; + killed.get_or_insert(now); + } + // Termination is asynchronous, and a process TerminateProcess can't end (stuck in + // the kernel) would hold the stop forever: give up on it, as on Unix. + if killed.is_some_and(|at| now.duration_since(at) >= DEBUGGEE_KILL_WAIT) { + tracing::warn!(session = s.id.0, pid, "stop: the debugged program did not exit after it was killed"); + break; } tokio::time::sleep(Duration::from_millis(50)).await; }