Repository navigation
Call GetResults for WinUI async actions on the owning JS thread - #237
Open
leileizhang (lei9444) wants to merge 1 commit into
Open
leileizhang (lei9444) wants to merge 1 commit into
leileizhang (lei9444) wants to merge 1 commit into
Conversation
Queue the completion notification, not the action. Keep the action in the environment registry until settlement or cleanup, including when queue shutdown falls back to Node. Data-returning and non-WinUI operations keep their existing result collection path. Call the void GetResults slot without a dummy output argument. Add a device-free native owner-thread action covering scheduled WinUI startup, shutdown draining, and a late error after unregister. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Mixed-language test coverageWorkflow status: ✅ Passed
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MediaCapture.InitializeWithSettingsAsynccould finish successfully on a WinUI STA while its JS Promise rejected withRPC_E_WRONG_THREAD. The bridge dispatched Promise settlement to the UI thread, but had already calledGetResultson a completion thread or an MTA worker. CallingGetResultson the same action on the originating thread succeeded.For
IAsyncActionandIAsyncActionWithProgressconverted to Promises while the WinUI queue is registered, retain the action in the JS environment and enqueue only the completion notification. The settling callback calls the real, zero-argumentGetResultson the owning thread, including when queue shutdown routes the callback through Node. Its HRESULT determines success or failure. Data-returning operations and actions without a registered WinUI queue keep their existing result collection path; no public JS API changes.Reproduction
Prerequisites: Windows with Node.js and the Rust/MSVC build tools. For the before/after comparison, set
$oldAddonto the absolute path of an unpatched.nodefile matching your Node architecture (for example, from0.1.0-preview.24). The fixture does not require a camera or a Windows App SDK installation.Steps:
From this PR's checkout, run
Set-Location .\bindings\js, thennpm ciandnpm run build.Run the same owner-thread action against both addons:
Actual behavior: The unpatched addon logs
GetResults failed: Async operation failed: 0x8001010E; the action's owner-thread implementation is never entered, and the assertion fails.After the fix: The test prints
dispatcher-shutdown-ok. The already-completed action runsGetResultsexactly once as the queue drains. An action that finishes after unregistering the queue still rejects with its actual0x80004005failure.Validation
On Windows ARM64,
npx --no-install ava __test__\index.spec.ts --match '*WinUI scheduled start*'passed with the generated WinUI Application and matching bootstrap DLL: the action settled beforeApplication.Startreturned. With only the native addon replaced, the Gallery initialized the real camera, displayed its preview, navigated away, and exited with no remaining active native objects or components.