Skip to content

Prevent .NET Framework telemetry consumer starvation - #10988

Merged
Amaury Levé (Evangelink) merged 1 commit into
mainfrom
dev/amauryleve/fix-ci-test-failures
Sep 3, 2026
Merged

Amaury Levé (Evangelink) merged 1 commit into
mainfrom
dev/amauryleve/fix-ci-test-failures

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Windows CI build 3065109 timed out in six .NET Framework telemetry tests because the AppInsights ingest loop could be starved when scheduled on the thread pool.

Run the .NET Framework consumer on a named dedicated thread and synchronously wait for channel data, while preserving the existing asynchronous thread-pool path on modern .NET. Complete the framework channel during cancellation so the dedicated consumer exits cleanly. Regression coverage verifies the dedicated scheduling path.

Validated with the Microsoft.Testing.Extensions unit tests on net462, net472, and net8.0.

Run the .NET Framework AppInsights ingest loop on a dedicated thread so thread-pool contention cannot delay telemetry processing and cause test timeouts.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 42fd90cd-4366-4b86-89ec-cda14f5f569f
Copilot AI balanced review requested due to automatic review settings September 3, 2026 09:42
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

🧪 Expert test review — PR #10988

No new or modified test methods were identified in the changed regions
of this PR. Nothing to review.

Re-run with /review-tests.

🤖 Automated content by GitHub Copilot. Generated by the Test Reviewer on PR (on open / sync) workflow. · auto · 36.7 AIC · ⌖ 2.42 AIC · ⊞ 16.9K · [◷]( · ◷)

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

🧵 Parallel-safety audit — PR #10988

Nothing audited here touches process-global state, shared filesystem paths, or
[ResourceLock] / [DoNotParallelize] declarations. Nothing to flag for
parallel-safety.

The only change is a new [TestMethod] (Constructor_StartsTelemetryConsumerOnDedicatedThread, #if !NETCOREAPP only) verifying the constructor calls ITask.RunLongRunning on a mocked ITask. It touches no environment variables, current directory, console, static/global fields, or filesystem paths, and declares no [ResourceLock]/[DoNotParallelize].

Audited Microsoft.Testing.Extensions.UnitTests at scope MethodLevel ([assembly: Parallelize(Scope = ExecutionScope.MethodLevel, Workers = 0)] in Program.cs), workers CPU count.

Re-run with /parallel-audit.

🤖 Automated content by GitHub Copilot. Generated by the Parallel-safety audit on PR (on open / sync) workflow. · auto · 35.5 AIC · ⌖ 3.69 AIC · ⊞ 24.8K · [◷]( · ◷)

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

🤖 Automated review by GitHub Copilot. Generated by the Expert Code Review workflow. To request a follow-up action, reply by tagging @copilot directly.

Review Summary

No blocking issues found. The change is well-structured and correct.

What was reviewed

Dimension Verdict
Correctness ✅ Clean
Thread Safety ✅ Clean
Backward Compatibility ✅ Clean
Public API Surface ✅ N/A — no public API changes
Performance ✅ Improved — avoids thread-pool starvation on .NET Framework
Resource Management ✅ Clean
Test Coverage ✅ New test added

Analysis

Design rationale is sound: On .NET Framework (!NETCOREAPP), the ingest loop now runs on a dedicated Thread via ITask.RunLongRunning instead of Task.Run. This avoids thread-pool starvation since the consumer now uses the synchronous WaitToRead() (which blocks via Monitor.Wait) rather than the async WaitToReadAsync. A thread-pool thread permanently blocked on Monitor.Wait would be wasted; a dedicated thread is the correct choice.

Cancellation path is correct: The !NETCOREAPP cancellation callback calls both _flushTimeoutOrStop.Cancel() and _payloads.Complete(). The Complete() call is necessary because synchronous WaitToRead() doesn't accept a CancellationToken — it wakes up only when items are enqueued or the channel is completed. The inner drain loop (line 185) checks _flushTimeoutOrStop.Token.IsCancellationRequested to exit promptly, so the two-step cancellation is correct.

VSTHRD103 suppression is justified: The pragma comment accurately explains that the consumer runs on a dedicated thread, making synchronous blocking safe.

Test coverage: The new Constructor_StartsTelemetryConsumerOnDedicatedThread test verifies that RunLongRunning (not Run) is called on the !NETCOREAPP path, with the expected thread name. Appropriately guarded by #if !NETCOREAPP.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The targeted scheduling change is consistent with the channel implementation and includes appropriate regression coverage.

Review tier: Balanced
Findings: None

What changed in this PR

Prevents .NET Framework telemetry ingestion from being starved by thread-pool contention.

Changes:

  • Runs the .NET Framework consumer on a dedicated named thread.
  • Completes the channel during cancellation to unblock synchronous reads.
  • Adds regression coverage for dedicated scheduling.
File Description
AppInsightsProvider.cs Implements dedicated-thread ingestion and cancellation cleanup.
AppInsightsProviderTests.cs Verifies .NET Framework uses RunLongRunning.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@Evangelink

Copy link
Copy Markdown
Member Author

/backport to rel/4.4

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

@Evangelink
Amaury Levé (Evangelink) merged commit 7ac4b21 into main Sep 3, 2026
28 of 32 checks passed
@Evangelink
Amaury Levé (Evangelink) deleted the dev/amauryleve/fix-ci-test-failures branch September 3, 2026 10:14
Amaury Levé (Evangelink) added a commit that referenced this pull request Sep 3, 2026
…#10988 (backport to rel/4.4) (#10989)

Co-authored-by: Amaury Levé <amauryleve@microsoft.com>
Copilot-Session: 42fd90cd-4366-4b86-89ec-cda14f5f569f
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