Repository navigation
Description
Repository: microsoft/winappCli
Component: src/winapp-CLI/WinApp.Cli/Services/XamlTriageService.cs — TryKill (L453-468), WaitUntilExited (L477-483)
Type: unbounded wait / missing cancellation
Summary
When the WinUI triage child exceeds its five-minute budget, the CLI kills it and then waits for it to
be really gone — in a loop with no deadline and no cancellation:
private void TryKill(Process process)
{
try
{
if (!process.HasExited)
{
process.Kill(entireProcessTree: true);
}
}
catch { /* raced its own exit, or could not be killed; wait for it below */ }
WaitUntilExited(process.WaitForExit, logger);
}
internal static void WaitUntilExited(Func<TimeSpan, bool> waitForExit, ILogger logger)
{
while (!waitForExit(KillExitWait)) // KillExitWait = 30 s
{
logger.LogDebug("Still waiting for the WinUI triage child to exit before releasing its debugger DLLs.");
}
}The wait is deliberate — the doc comment explains that the verified debugger DLLs must stay held until
the child is truly gone, because releasing them early reopens a window in which a still-running child
could load a swapped file. What it does not have is any way out: KillExitWait bounds one wait, not
the loop, and the CancellationToken the surrounding method already carries is not passed in.
Expected behavior
The safety requirement — do not release the DLL hold while the child lives — is kept, and the user
still gets control back: the wait honours the command's cancellation token (Ctrl+C, or the host
shutting down), and if the child cannot be reaped the command reports that instead of blocking
forever. The DLL hold can be kept for the process lifetime without keeping the command alive.
Actual behavior
If the killed child does not exit, the CLI never returns. Driven by calling the shipped
WaitUntilExited with a waitForExit that always reports "not yet exited", the way TryKill calls
it:
child that never exits: still looping after 65,013 ms (3 x 30 s waits, no local exit)
CPU during that time: 141 ms (blocked in the wait, not spinning)
child that does exit: returns in 271 ms
The loop is not busy (it sleeps inside WaitForExit), and it re-logs every 30 s, so the command looks
alive while making no progress — and Ctrl+C does not stop it, because the token is never consulted
here.
Root cause
WaitUntilExited takes only a wait delegate and a logger. The while condition can therefore only be
"did it exit yet", which has no third state, and the author had no way to express "or the caller gave
up" without changing the signature.
TryKill has the command's CancellationToken in scope at its call site but does not pass it, and
the doc comment reasons only about the DLL-release ordering — not about the command's own liveness.
Impact
A child that survives Kill(entireProcessTree: true) — a process wedged in an uninterruptible wait, a
grandchild that escaped the tree, a debugger holding a handle — turns a five-minute timeout into a
permanent hang. The terminal is stuck, the verified DLLs stay held for the life of the process, and
the only recovery is to kill the CLI itself (or the terminal). Ctrl+C does not help.
The path is reached exactly when something has already gone wrong (the triage exceeded five minutes
and had to be killed), which is the situation in which a wedged child is most likely.
Suggested fix
Keep the safety property and add an exit:
internal static bool WaitUntilExited(Func<TimeSpan, bool> waitForExit, ILogger logger,
CancellationToken cancellationToken, TimeSpan? giveUpAfter = null)
{
var deadline = giveUpAfter is { } limit ? DateTime.UtcNow + limit : (DateTime?)null;
while (!waitForExit(KillExitWait))
{
if (cancellationToken.IsCancellationRequested) { logger.LogWarning("…cancelled…"); return false; }
if (deadline is { } d && DateTime.UtcNow >= d) { logger.LogWarning("…still running after {T}; leaving its DLL hold in place…"); return false; }
}
return true;
}and have TryKill pass the command token. Returning false lets the caller report "the triage child
could not be stopped" while keeping the hold decision explicit, instead of blocking the process.
Activity
soarkit commentedon Nov 16, 2026