Skip to content

Fix UniversalBGTask crash and gracefully handle CoCreateInstance failures#6507

Open
godlytalias wants to merge 1 commit into
mainfrom
user/godlytalias/fix-universalbgtask-crash
Open

Fix UniversalBGTask crash and gracefully handle CoCreateInstance failures#6507
godlytalias wants to merge 1 commit into
mainfrom
user/godlytalias/fix-universalbgtask-crash

Conversation

@godlytalias
Copy link
Copy Markdown
Contributor

Issue

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<winrt::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 existing THROW_IF_FAILED provided 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.

PR Checklist

…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>
@godlytalias
Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants