[2.0 Servicing] Fix UniversalBGTask crash and gracefully handle CoCreateInstance failures#6568
Open
godlytalias wants to merge 5 commits into
Conversation
…ures (#6507) UniversalBGTask::Task::Run could crash backgroundTaskHost.exe in two scenarios: 1. When LocalSettings has no entry for the task's TaskId, ApplicationDataContainerSettings::Lookup returns S_OK with a null IInspectable. The subsequent unbox_value<guid> then throws hresult_no_interface, and because the broker treats the failure as transient it re-fires the trigger forever. 2. When CoCreateInstance fails (e.g. the COM class isn't registered against the package), the wrapped THROW_IF_FAILED produced no diagnostic context. Fix: - If LocalSettings.Lookup returns null, log via wil and unregister the orphaned OS task so the broker stops re-firing it. - If CoCreateInstance fails, log the HR with the CLSID and TaskId and return cleanly. The registration is left in place so the broker can retry on the next trigger in case the failure is transient. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…fix (bug 62755661) Wrap the crash-hardening behavior behind WINAPPSDK_CHANGEID_62755661 (WinAppSDK_2_2_2) and add the RuntimeCompatibilityChange.UniversalBGTask_RunCrash enum entry so apps can opt out via RuntimeCompatibilityOptions.
Contributor
Author
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
…bgtask-crash-on-release-2.0-stable
Contributor
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
agniuks
reviewed
Jun 18, 2026
Co-authored-by: agniuks <41223743+agniuks@users.noreply.github.com>
Contributor
Author
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
…rsalBGTaskDLL Task.cpp now includes <FrameworkUdk/Containment.h> for the containment fix, but WindowsAppRuntime_UniversalBGTaskDLL.vcxproj did not import the Microsoft.FrameworkUdk targets, so the FrameworkUdk include directory was missing from the compiler command line, causing: Task.cpp(10,10): error C1083: Cannot open include file: 'FrameworkUdk/Containment.h': No such file or directory Import Microsoft.FrameworkUdk.targets (which adds the include path and the Microsoft.Internal.FrameworkUdk.lib link dependency) plus the matching package-restore Error check, mirroring the existing pattern used by Microsoft.Windows.ApplicationModel.Resources.vcxproj and other Containment consumers. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
Author
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
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.
UniversalBGTask::Task::Run could crash backgroundTaskHost.exe in two scenarios:
When LocalSettings has no entry for the task's TaskId, ApplicationDataContainerSettings::Lookup returns S_OK with a null IInspectable. The subsequent unbox_valuewinrt::guid then throws hresult_no_interface, and because the broker treats the failure as transient it re-fires the trigger forever.
When CoCreateInstance fails (e.g. the COM class isn't registered against the package), the wrapped THROW_IF_FAILED produced no diagnostic context.
Fix
Servicing
WINAPPSDK_CHANGEID_62755661(WinAppSDK_2_2_2); the original (throwing) behavior is preserved in theelsebranch for apps pinned to an earlier patch level.UniversalBGTask_RunCrash = 62755661.Cherry picked from #6507