Repository navigation
Prevent .NET Framework telemetry consumer starvation - #10988
Conversation
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
🧪 Expert test review — PR #10988No new or modified test methods were identified in the changed regions Re-run with
|
🧵 Parallel-safety audit — PR #10988Nothing audited here touches process-global state, shared filesystem paths, or The only change is a new Audited Re-run with
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
/backport to rel/4.4 |
|
Started backporting to rel/4.4: https://github.com/microsoft/testfx/actions/runs/33741481819 |
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.