Repository navigation
Stop winapp run hanging when several packaged launches deploy at once - #1058
Conversation
Package deployment awaits now leave the WinRT completion callback before continuing, so app activation no longer runs inside that callback. App activation is also bounded by a 2-minute timeout with a clear error. Fixes #1035 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0f5f2312-a548-4c59-a784-016bc0a48ebe
|
Nikola Metulev (@nmetulev) I couldn't reproduce the #1035 hang locally, so this is a best-guess fix. What I tried on Windows 10.0.26310 ARM64 (the issue was on 28000 ARM64):
What I did confirm: after a fresh registration, Could you run this branch against your repro on 28000 to confirm it fixes the hang? |
There was a problem hiding this comment.
🔵 Needs a closer look
Release build and 88 targeted tests pass, but the low-level WinRT concurrency failure was not reproducible, so the mitigation needs final human review.
0 open findings
What changed in this PR
Prevents concurrent packaged-app launches from hanging during Windows deployment callbacks and adds a bounded activation timeout.
Changes:
- Resumes package operations off WinRT completion threads.
- Runs application activation asynchronously with a two-minute timeout.
- Adds regression tests for callback threading, timeouts, and exception propagation.
| File | Description |
|---|---|
PackageRegistrationService.cs |
Moves post-deployment continuations to the thread pool. |
AppLauncherService.cs |
Adds bounded off-thread activation. |
PackageRegistrationServiceTests.cs |
Tests callback-thread separation. |
AppLauncherServiceTests.cs |
Tests timeout and exception behavior. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0f5f2312-a548-4c59-a784-016bc0a48ebe
Build Metrics ReportValidation passed. All required build and validation jobs succeeded. Binary Sizes
.NET Test Results (TRX reports)Other suites are reflected in the overall validation status above. ✅ 8335 passed, 37 skipped out of 8372 tests in 1266.1s (+4 tests, +94.2s vs. baseline) Test Coverage✅ 87.5% line coverage, 82.2% branch coverage · ✅ no change vs. baseline CLI Startup Time64ms median (x64, Try This BuildInstalls the MSIX for your architecture, replacing any previously installed build. Needs the GitHub CLI — the command offers to install it and sign you in if it is missing. & ([scriptblock]::Create((irm https://raw.githubusercontent.com/microsoft/winappCli/main/scripts/winapp-pr.ps1))) 1058Switching between builds often?Put the tool on your PATH once: & ([scriptblock]::Create((irm https://raw.githubusercontent.com/microsoft/winappCli/main/scripts/winapp-pr.ps1))) -AddToPathThen this build is just: winapp-pr 1058Run Updated 2026-10-10 19:25:21 UTC · commit |
Description
winapp runcould hang forever inIApplicationActivationManager.ActivateApplicationwhen several packaged-app launches ran at once (#1035).Likely cause: the CLI has no synchronization context. When a
PackageManagerdeploy/remove/add operation finishes, the code afterawaitruns inline on the WinRT completion-callback thread. So after a fresh registration, the whole rest ofwinapp run, including app activation, ran inside the deployment callback. Stack traces confirmActivateApplicationwas called beneathAsyncInfoToTaskBridge.Complete. With several deployments in flight, activation from inside that callback can plausibly wait on deployment work that is waiting on the callback.Changes:
PackageRegistrationService: everyPackageManagerawait now yields to the thread pool after it completes, so later work never runs on the deployment callback thread.ConfigureAwaitOptions.ForceYieldingis not enough here, because it only affects tasks that are already complete.AppLauncherService.LaunchByAumid: activation runs on a pool thread with a 2-minute timeout. If Windows never answers, the user gets an actionable error instead of a hang:Activation failures keep their original exception type, so existing error messages are unchanged.
Usage Example
No command changes. Concurrent
winapp run <folder> --detachinvocations should all return.Related Issue
Fixes #1035
Type of Change
Checklist
Screenshots / Demo
N/A
Additional Notes
I couldn't reproduce the hang, so this is a best-guess fix. Tested on Windows 10.0.26310 ARM64; the reporter used 28000 ARM64.
--detach --without-alias: many rounds, fresh and existing registrations. No hang.dotnet new winuiprojects launched concurrently: 15 rounds, with and without--no-build. No hang.What was confirmed: before the fix,
ActivateApplicationruns inside the deployment completion callback (AsyncInfoToTaskBridge.Completeis on the stack). After the fix, that frame is gone, and 3 concurrent rounds still pass. Repeated runs skip re-registration when the manifest hasn't changed, which hides this path.Validation:
dotnet test --project src/winapp-CLI/WinApp.Cli.Tests/WinApp.Cli.Tests.csproj -c Debug --filter "...AppLauncherServiceTests|PackageRegistrationService|GuestLaunchCommandTests|RunCommandTests|MsixService": 568 passed, 0 failed, on the rebased head.OffDeploymentCallback_ContinuationDoesNotRunOnCompletingThread: fails when the yield is removed (negative control) and passes with it.LaunchByAumid_ActivationNeverReturns_ThrowsTimeoutExceptionandLaunchByAumid_ActivatorThrows_PropagatesOriginalException: pass.