Handle ServerNotAvailableException in CollectLinuxCommand process probing#5705
Open
Handle ServerNotAvailableException in CollectLinuxCommand process probing#5705
Conversation
Copilot
AI
changed the title
[WIP] Investigate DiagnosticsClient.GetProcessInfo exception
Handle ServerNotAvailableException in CollectLinuxCommand process probing
Feb 5, 2026
8fe26f7 to
fe76ee6
Compare
…lpers Add UserEventsProbeResult enum (Supported/NotSupported) to replace boolean return. Introduce ProbeProcess helper for probing a single process. Add GetAndProbeAllProcesses helper that enumerates and probes all published processes. Update callers in CollectLinux and SupportsCollectLinux to use new helpers. Update BuildProcessSupportCsv to use UserEventsProbeResult enum.
…cess probing Add ProcessNotFound and ConnectionFailed values to UserEventsProbeResult enum. Update ProbeProcess to catch DiagnosticToolException (process resolution failed) and ServerNotAvailableException (diagnostic endpoint not accessible) separately. Add FormatProcessIdentifier helper for clean display of process ID/name. Add unknownProcesses/unknownCsv tracking for processes that could not be probed. Update probe mode output to show 'Processes that could not be probed' section. Include 'unknown' value in CSV output for unprobed processes. Update non-probe mode to show distinct errors for each failure type. Change '.NET process' to 'Process' in messages since arbitrary PIDs may not be .NET. Fixes #5694
Document that results are categorized as supported, not supported, or unknown. Clarify that unknown status occurs when diagnostic endpoint is not accessible.
…iled handling Update test expectations to match new behavior: - Add FormatProcessNotFoundError and FormatProcessIdentifier helpers - Update ResolveProcessExceptions test data for ProcessNotFound handling - Update probe error test cases for process resolution errors - Tests now expect ReturnCode.TracingError for failures in non-probe mode - Tests expect ReturnCode.Ok for probe mode with informational output
fe76ee6 to
0cbcf44
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves dotnet-trace collect-linux resilience by handling process-resolution and diagnostics-connection failures during “process probing” so the command no longer crashes when a target process can’t be resolved or connected to (e.g., exits between enumeration and probing, cross-container endpoint issues).
Changes:
- Replaced boolean “supports” probing with a 4-state probe result (Supported/NotSupported/ProcessNotFound/ConnectionFailed) and updated user-facing output.
- Updated machine-wide probe to track and report “unknown/unprobed” processes and emit
unknownin CSV. - Adjusted functional tests to match new probe behaviors/messages (partially—some existing expectations still appear outdated).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
src/Tools/dotnet-trace/CommandLine/Commands/CollectLinuxCommand.cs |
Introduces multi-state probing, catches DiagnosticToolException/ServerNotAvailableException, updates probe messaging and CSV output. |
src/tests/dotnet-trace/CollectLinuxCommandFunctionalTests.cs |
Updates/extends tests for new probe outcomes and adds helpers for the new process identifier/message formatting. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/Tools/dotnet-trace/CommandLine/Commands/CollectLinuxCommand.cs
Outdated
Show resolved
Hide resolved
src/Tools/dotnet-trace/CommandLine/Commands/CollectLinuxCommand.cs
Outdated
Show resolved
Hide resolved
src/Tools/dotnet-trace/CommandLine/Commands/CollectLinuxCommand.cs
Outdated
Show resolved
Hide resolved
src/Tools/dotnet-trace/CommandLine/Commands/CollectLinuxCommand.cs
Outdated
Show resolved
Hide resolved
src/Tools/dotnet-trace/CommandLine/Commands/CollectLinuxCommand.cs
Outdated
Show resolved
Hide resolved
src/Tools/dotnet-trace/CommandLine/Commands/CollectLinuxCommand.cs
Outdated
Show resolved
Hide resolved
noahfalk
reviewed
Feb 6, 2026
…-diagnostics-client-exception
…codes Per review feedback, single-process paths (explicit -p PID or -n NAME) now call CommandUtils.ResolveProcess separately so argument validation errors propagate with original specific messages and ArgumentError return code. ProbeProcess is only used for the resolved PID's runtime check and connection attempt. Restore '.NET process(es)' wording in probe output messages. Remove unused FormatProcessIdentifier helper from both source and tests. Revert probe error tests to expect ArgumentError with original messages. Revert ResolveProcessExceptions test data to original error text. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The supportedCsv, unsupportedCsv, and unknownCsv variables are always non-null when the CsvToConsole and Csv output blocks are reached, since generateCsv is true for those modes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
noahfalk
reviewed
Mar 7, 2026
src/Tools/dotnet-trace/CommandLine/Commands/CollectLinuxCommand.cs
Outdated
Show resolved
Hide resolved
Update connection failure messages per review: use 'diagnostic port' instead of 'diagnostic endpoint', and reword to indicate the process may not have a .NET diagnostic port rather than implying it exists but is inaccessible. Skip processes that exit during name resolution silently rather than reporting them as unknown, per reviewer suggestion that users wouldn't find it surprising. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Handle
ServerNotAvailableExceptionandDiagnosticToolExceptioninCollectLinuxCommandprocess probing to gracefully handle processes that cannot be resolved or connected to.Fixes #5694
Problem
DiagnosticsClient.GetProcessInfo()throwsServerNotAvailableExceptionwhen the diagnostics server is unavailable (process exits between enumeration and probing, connection failures, etc.). Additionally,CommandUtils.ResolveProcess()throwsDiagnosticToolExceptionfor invalid process IDs or names. These unhandled exceptions caused probe operations to crash.Solution
Introduce a four-state probe result to handle all outcomes:
name)
Behavior Changes
Non-probe mode (
dotnet-trace collect-linux -p <pid>):ProcessNotFound:[ERROR] Could not resolve process '<id>'.ConnectionFailed:[ERROR] Unable to connect to process '<id>'. The process may have exited or its diagnostic endpoint is not accessible.TracingErrorSingle-process probe mode (
dotnet-trace collect-linux --probe -p <pid>):ProcessNotFound:Could not resolve process '<id>'.ConnectionFailed:Process '<id>' could not be probed. Unable to connect to the process's diagnostic endpoint.Ok(informational output)Machine-wide probe mode (
dotnet-trace collect-linux --probe):unknownvalue for unprobed processesOther Changes
FormatProcessIdentifierhelper - showsname (pid)when name is provided, justpidotherwise--probeoption help text to document result categories