Skip to content

Fix DrainPacketQueue threads leaking - #14135

Merged
AlesProkop merged 3 commits into
dotnet:mainfrom
Erarndt:dev/erarndt/threadLeak
Jun 23, 2026
Merged

AlesProkop merged 3 commits into
dotnet:mainfrom
Erarndt:dev/erarndt/threadLeak

Conversation

@Erarndt

@Erarndt Erarndt commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Fixes #

Context

DrainPacketQueue() has a dedicated thread for processing, and for long-lived hosts, these threads can be left alive due to an error that is swallowed.

Changes Made

We can check for the exit condition outside of the try block so that exceptions don't skip the check.

Testing

Notes

Copilot AI review requested due to automatic review settings June 22, 2026 21:01

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.

Pull request overview

This PR fixes a potential leak of the dedicated DrainPacketQueue thread in NodeProviderOutOfProcBase.NodeContext by ensuring the “exit packet” termination condition is evaluated even when the write path throws (e.g., broken/disposed pipe), which is particularly important for long-lived hosts like Visual Studio.

Changes:

  • Moves the NodeBuildComplete exit/return logic out of the packet write try block so it runs even when write exceptions are swallowed.
  • Adds a detailed comment explaining the leak scenario and why the check must run after the exception handling.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@AlesProkop
AlesProkop enabled auto-merge (squash) June 23, 2026 12:34
@AlesProkop
AlesProkop merged commit 538532e into dotnet:main Jun 23, 2026
14 checks passed
ViktorHofer pushed a commit that referenced this pull request Jun 29, 2026
Quarantines 5 flaky tests detected by the automated flaky-test detector
across `main` rolling builds and approved PRs. All failures are confined
to Windows legs (`FullOnWindows`, `FullOnWindows Release`,
`CoreOnWindows`) with `net472` TFM, so each is scoped with
`TestPlatforms.Windows`.

---

## 1. `CoordinatorServer_Tests.ConcurrentClients_AllReceiveGrants`

**Flaky-test key** (automated de-duplication — do not edit):
```text
flaky-test-id: Microsoft.Build.Coordinator.UnitTests.CoordinatorServer_Tests.ConcurrentClients_AllReceiveGrants
```

**Action:** Quarantine (6a)  
Tracked by #14193

- **Distinct sources:** 7 (3 PRs + 4 rolling `main` builds)
- **PRs:** #14104, #14130, #14135
- **Rolling builds:**
[1472231](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1472231),
[1472331](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1472331),
[1477803](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1477803),
[1478840](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1478840)
- **Legs:** CoreOnWindows, FullOnWindows, FullOnWindows Release |
**TFM:** net472
- **First seen:** 2026-06-19  |  **Last seen:** 2026-06-24
- **Sample error:** `System.IO.IOException: The semaphore timeout period
has expired.`

---

## 2. `MSBuildServer_Tests.CanShutdownServerProcess`

**Flaky-test key** (automated de-duplication — do not edit):
```text
flaky-test-id: Microsoft.Build.Engine.UnitTests.MSBuildServer_Tests.CanShutdownServerProcess
```

**Action:** Quarantine (6a)  
Tracked by #14195

- **Distinct sources:** 3 (rolling `main` builds only)
- **Rolling builds:**
[1464065](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1464065),
[1475010](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1475010),
[1481906](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1481906)
- **Legs:** FullOnWindows, FullOnWindows Release  |  **TFM:** net472
- **First seen:** 2026-06-15  |  **Last seen:** 2026-06-25
- **Error hashes:** 4 distinct signatures
- **Sample error:** `System.InvalidOperationException: Couldn't get
process information from performance counter.`

---

## 3. `XMakeAppTests.GetCommandLine`

**Flaky-test key** (automated de-duplication — do not edit):
```text
flaky-test-id: Microsoft.Build.UnitTests.XMakeAppTests.GetCommandLine
```

**Action:** Quarantine (6a)  
Tracked by #14194

- **Distinct sources:** 3 (rolling `main` builds only)
- **Rolling builds:**
[1464065](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1464065),
[1475010](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1475010),
[1481906](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1481906)
- **Legs:** FullOnWindows, FullOnWindows Release  |  **TFM:** net472
- **First seen:** 2026-06-15  |  **Last seen:** 2026-06-25
- **Error hashes:** 4 distinct signatures
- **Sample error:** command-line path assertion mismatch on Windows
(`ShouldContain` failure for `MSBuild.exe /v:diag` path)

---

## 4. `XMakeAppTests.GetCommandLineQuotedExe`

**Flaky-test key** (automated de-duplication — do not edit):
```text
flaky-test-id: Microsoft.Build.UnitTests.XMakeAppTests.GetCommandLineQuotedExe
```

**Action:** Quarantine (6a)  
Tracked by #14192

- **Distinct sources:** 3 (rolling `main` builds only)
- **Rolling builds:**
[1464065](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1464065),
[1475010](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1475010),
[1481906](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1481906)
- **Legs:** FullOnWindows, FullOnWindows Release  |  **TFM:** net472
- **First seen:** 2026-06-15  |  **Last seen:** 2026-06-25
- **Error hashes:** 4 distinct signatures
- **Sample error:** command-line path assertion mismatch on Windows
(`ShouldContain` failure for `MSBuild.exe /v:diag` path)

---

## 5. `XMakeAppTests.GetCommandLineQuotedExeOnPath`

**Flaky-test key** (automated de-duplication — do not edit):
```text
flaky-test-id: Microsoft.Build.UnitTests.XMakeAppTests.GetCommandLineQuotedExeOnPath
```

**Action:** Quarantine (6a)  
Tracked by #14196

- **Distinct sources:** 3 (rolling `main` builds only)
- **Rolling builds:**
[1464065](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1464065),
[1475010](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1475010),
[1481906](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1481906)
- **Legs:** FullOnWindows, FullOnWindows Release  |  **TFM:** net472
- **First seen:** 2026-06-15  |  **Last seen:** 2026-06-25
- **Error hashes:** 4 distinct signatures
- **Sample error:** command-line path assertion mismatch on Windows
(`ShouldContain` failure for `MSBuild.exe /v:diag` path)




> Generated by [Flaky Test
Triage](https://github.com/dotnet/msbuild/actions/runs/28321861359) ·
610.5 AIC · ⊞ 34.9K ·
[◷](https://github.com/search?q=repo%3Adotnet%2Fmsbuild+%22gh-aw-workflow-id%3A+flaky-test-detector.agent%22&type=pullrequests)

<!-- gh-aw-agentic-workflow: Flaky Test Triage, engine: copilot,
version: 1.0.60, model: claude-sonnet-4.6, id: 28321861359, workflow_id:
flaky-test-detector.agent, run:
https://github.com/dotnet/msbuild/actions/runs/28321861359 -->

<!-- gh-aw-workflow-id: flaky-test-detector.agent -->
<!-- gh-aw-workflow-call-id: dotnet/msbuild/flaky-test-detector.agent
-->

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

5 participants