Skip to content

winapp ui triage waits for a killed child with no deadline and no way to cancel #1324

Open

Description

@soarkit

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

  1. soarkit commented on Nov 16, 2026

    @soarkit
    Author

    Three corrections to my own report.

    1. The command name is wrong. This is not winapp ui triage — the path is the crash-analysis /
      run --debug-output route, which re-invokes the hidden __xaml-triage verb.
    2. My suggested fix breaks the safety property it was meant to keep. Returning false from
      WaitUntilExited makes TryAnalyzeAsync return, and its using var binaries / using var extension (L68/L76) dispose the held FileStream (VerifiedTool.cs:79) while the child may
      still be running — exactly the window the doc comment forbids. Any "give up" path has to keep
      the hold, not release it.
    3. "Permanent hang" is overstated. Ctrl+C terminates the console app, so the user is not
      actually stuck without recourse; what is missing is a bounded wait and a diagnostic that says
      the child could not be reaped.

    Corrected direction: keep the hold for the process lifetime (leak it deliberately if the child
    never exits) but stop blocking the command — report "the triage child could not be stopped; its
    DLL hold is kept until this process exits" and return. The token question is moot in this path: the
    call chain (CrashDumpService.RunXamlTriageGuardedAsync, L339) never threads one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions