Skip to content

Fix AzureDevOpsReport teardown crash and silent live-publishing failures by @Evangelink in #10291 (backport to rel/4.3) - #10504

Merged
Amaury Levé (Evangelink) merged 8 commits into
microsoft:rel/4.3from
nohwnd-bot:backport/10291/to/rel/4.3
Aug 7, 2026
Merged

Amaury Levé (Evangelink) merged 8 commits into
microsoft:rel/4.3from
nohwnd-bot:backport/10291/to/rel/4.3

Conversation

@nohwnd-bot

Copy link
Copy Markdown
Contributor

Backport of #10291 to rel/4.3

/cc Amaury Levé (@Evangelink)

The Azure DevOps live test-results publisher is disposed twice during
teardown (once when the test host disposes its services, once again during
process shutdown). Its Dispose() called Cancel() on an already disposed
CancellationTokenSource, which crashed the test host with an unhandled
ObjectDisposedException after all tests had passed and after results had
already been published. microsoft#10195 removed one duplicate-dispose path inside a
single disposal pass but the crash still reproduces end to end, so make
Dispose() idempotent.

The follow-up symptom (no crash, but no published results) has the same
root cause surface: when the Azure DevOps environment is incomplete the
publisher silently disabled itself from IsEnabledAsync and only logged to
the diagnostic file log, so users saw neither a test run nor a reason.
Keep the extension enabled whenever --publish-azdo-test-results is set and
report the missing configuration on the output device instead.

Fixes microsoft#10191

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: b564deae-b8d2-49aa-96d3-9308ec461d89
…ures

- WarnAsync no longer propagates output-device exceptions. It is called from
  error-recovery paths and from session teardown, where CommonTestHost does not
  guard lifetime handlers, so a throw would have turned a diagnostic warning
  into a failed run - the same class of bug this change set fixes.
- Reset the publisher state before reporting the run-creation failure so a
  display failure can never leave it half-initialized.
- Route the post-run failures through the output device too. These are the ones
  that produce the reported symptom: a run left in InProgress does not appear in
  the Tests tab, and results left in the retry queue after the session-end flush
  are never retried. Report dropped results once with a count rather than per
  failed batch, to avoid spamming a warning every flush interval.
- Replace the double-dispose-without-session test, which passed with and without
  the fix, by one covering the inert-but-registered path that keeping the
  extension enabled now creates (ConsumeAsync/OnTestSessionFinishingAsync/Dispose
  on a misconfigured publisher).

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: b564deae-b8d2-49aa-96d3-9308ec461d89
…ting, message accuracy

- Attachment failures were still log-only. They are swallowed per attachment so
  one bad file cannot abort the drain, which made the outer catch unreachable and
  the changelog claim wrong. Count them at the real failure sites (run-level,
  result-level, and the batch skipped when result IDs cannot be parsed) and
  report one summary at session end. Coverage files and dumps no longer go
  missing without explanation.
- ConsumeAsync renewed the coordination lease before enqueuing the result, so an
  I/O failure there dropped the result before it reached a queue and the
  end-of-session count could not see it. Enqueue first.
- WarnAsync's fallback reused 'failed to publish test results' for a failure to
  write to the output device, which in the finalize path claimed results had
  failed to publish when they had all succeeded. Use a dedicated message.
- Make the missing-configuration warning provably non-null via [NotNullWhen(false)]
  rather than falling back to the unformatted resource string, which would have
  shown a raw '{0}' on the console.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: b564deae-b8d2-49aa-96d3-9308ec461d89
Per-attachment failures are counted inside UploadResultAttachmentsAsync, so the
only non-cancellation exception the surrounding catch can see is one thrown by
RenewLeaseAsync - in which case no upload is attempted and the whole attachment
set was dropped without being counted, making the end-of-session summary
under-report. Assert the summary from the existing result-attachment failure test
so the common counting path is covered.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: b564deae-b8d2-49aa-96d3-9308ec461d89
WarnAsync documents a never-throws contract but called _logger.LogWarning
outside any guard. Logger invokes each registered provider directly, so a
failing provider propagated out of the helper - including out of its own
catch block, where it replaced the exception being handled. Route both
logging attempts through TryLogWarning so a broken diagnostic logger can
neither suppress the output-device attempt nor escape the recovery path.

Run finalization excluded OperationCanceledException from its catch, but it
runs on its own cleanupCts rather than the session token, so an expiry there
(or an HttpClient TaskCanceledException) escaped this lifetime handler and
could fail an otherwise successful run - exactly the teardown crash this
change set exists to prevent. Treat it like the other finalization failures.

Both regressions are covered by tests that fail when the fix is reverted.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: b564deae-b8d2-49aa-96d3-9308ec461d89
OnTestSessionFinishingAsync is a lifetime handler and the platform does not
guard those, so a throwing log provider in its recovery catches escaped and
failed an otherwise successful run - the same defect already fixed inside
WarnAsync, one frame away. Route the background-flush and session-end flush
catches through TryLogWarning, plus the matching ConsumeAsync catch so the
recovery paths are consistent.

Covered by a test that drives a publish failure and then breaks the log
provider before teardown; it fails when the guard is reverted.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: b564deae-b8d2-49aa-96d3-9308ec461d89
The test only asserted that one line reached the output device, so a mutation
emitting an arbitrary string or the wrong resource key would have survived.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: b564deae-b8d2-49aa-96d3-9308ec461d89
A throwing log provider escaping these catches did more than fail the run: it
aborted the attachment drain so the rest of the queue was never attempted and
never counted, and when it escaped the per-attachment catch the caller treated
it as a pre-upload lease failure and added the whole attachment set again,
double-counting failures and mis-reporting successful uploads as failed.

Route every recovery-path log in the publisher through TryLogWarning so the
loops continue and the end-of-session counts stay accurate. The invariant is
now checkable: the only direct _logger.LogWarning call left is the one inside
TryLogWarning itself.

Covered by a test that fails two run attachments with a broken log provider and
asserts both are attempted and counted; it fails when the guard is reverted.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: b564deae-b8d2-49aa-96d3-9308ec461d89
@Evangelink
Amaury Levé (Evangelink) enabled auto-merge (squash) August 7, 2026 10:39
@Evangelink
Amaury Levé (Evangelink) merged commit 479a5c5 into microsoft:rel/4.3 Aug 7, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants