Fix UniversalBGTask crash and gracefully handle CoCreateInstance failures#6507
Open
godlytalias wants to merge 1 commit into
Open
Fix UniversalBGTask crash and gracefully handle CoCreateInstance failures#6507godlytalias wants to merge 1 commit into
godlytalias wants to merge 1 commit into
Conversation
…ures 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>
jonwis
approved these changes
May 26, 2026
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.
Issue
UniversalBGTask::Task::Runcould crashbackgroundTaskHost.exein two scenarios:LocalSettingshas no entry for the task'sTaskId,ApplicationDataContainerSettings::LookupreturnsS_OKwith a nullIInspectable. The subsequentunbox_value<winrt::guid>then throwshresult_no_interface, and because the broker treats the failure as transient it re-fires the trigger forever.CoCreateInstancefails (e.g. the COM class isn't registered against the package), the existingTHROW_IF_FAILEDprovided no diagnostic context.Fix
LocalSettings.Lookupreturns null, log viawilandUnregisterthe orphaned OS task so the broker stops re-firing it.CoCreateInstancefails, 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.PR Checklist