Repository navigation
Harden exceptions when connecting to server - #14292
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR hardens MSBuild Server client behavior by broadening exception handling around server-state detection (mutex checks / launch mutex acquisition) so unexpected, non-critical failures don’t escape and instead trigger a structured fallback.
Changes:
- Wrap
ServerNamedMutex.WasOpenin a non-critical exception filter and treat failures as “not open”, with tracing. - Broaden
MSBuildClientserver-state exception handling fromIOExceptionto any non-criticalException(still excludingPathTooLongException), mapping failures toUnknownServerState.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Build/BackEnd/Node/ServerNamedMutex.cs | Adds exception handling + trace logging around Mutex.TryOpenExisting to avoid propagating non-critical failures. |
| src/Build/BackEnd/Client/MSBuildClient.cs | Broadens catch filters during server-state checks / launch-mutex acquisition to avoid crashing and return UnknownServerState. |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Caution
agentic threat detected
Threat detection flagged this output in warn mode. Manual review is REQUIRED before any follow-up automation.
Review — Harden exceptions when connecting to server
The approach is sound: broadening from catch (IOException) to catch (Exception when !IsCritical) is the established MSBuild idiom (used in NodeEndpointOutOfProcBase, NodePipeServer, etc.) and correctly handles the Win32Exception("Connection timed out") root cause from #7993. One concrete correctness gap and two documentation/diagnostics improvements are worth addressing.
| # | Dimension | Verdict |
|---|---|---|
| 22 | Correctness & Edge Cases | 🟠 MODERATE |
| 18 | Documentation Accuracy | 🟠 MODERATE |
| 4 | Test Coverage & Completeness | 🟡 MAJOR |
| 6/14 | Logging & Diagnostics / Naming | 🔵 NIT |
✅ 20/24 dimensions clean.
- Correctness —
WasOpen()catch (line 46) lacks&& ex is not PathTooLongException, silently swallowing the exception that bothMSBuildClient.cscatch blocks explicitly re-throw. See inline comment onServerNamedMutex.cs:46. - Documentation — Deleted comments were the only explanation for why
Exceptionis caught instead ofIOExceptionand whyPathTooLongExceptionis excluded. A future contributor with no context will "fix" it back. See inline comment onMSBuildClient.cs:218. - Test Coverage — The core fix (
WasOpenreturningfalseinstead of throwing on non-IOException) has no regression test. SinceMutex.TryOpenExistingcan't be injected today, a minimal approach is an integration-level test that verifiesExecute()returnsUnknownServerState(not a crash) when given a mutex name that causes a non-IOException. At minimum, thePathTooLongExceptionpropagation contract should be verified. - Logging —
TryLaunchServer()'s catch emits the same"Failed to obtain the current build server state"message asExecute()'s catch, making the two failure modes indistinguishable in a trace log. See inline comment onMSBuildClient.cs:468.
Generated by Expert Code Review (on open) for #14292 · 1.3K AIC · ⊞ 30.4K
… fallback comments Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Harden exceptions when connecting to server