Skip to content

Fix issue in Collect-linux probing where process may have exited between enumeration and usage.#5778

Merged
hoyosjs merged 1 commit intodotnet:mainfrom
hoyosjs:juhoyosa/fix-flakey-test
Mar 25, 2026
Merged

Fix issue in Collect-linux probing where process may have exited between enumeration and usage.#5778
hoyosjs merged 1 commit intodotnet:mainfrom
hoyosjs:juhoyosa/fix-flakey-test

Conversation

@hoyosjs
Copy link
Copy Markdown
Member

@hoyosjs hoyosjs commented Mar 24, 2026

Fixes #5776
Fixes issues seen in CollectLinuxCommand_Probe_ListsProcesses_WhenNoArgs and CollectLinuxCommand_Probe_Csv

@hoyosjs hoyosjs requested a review from a team as a code owner March 24, 2026 23:50
Copilot AI review requested due to automatic review settings March 24, 2026 23:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 aims to stabilize dotnet-trace collect-linux --probe on Linux by handling the case where a target process exits between being enumerated and being probed, addressing intermittent failures like those reported in #5776.

Changes:

  • Add exception handling around per-process probing during --probe enumeration to skip processes that disappear mid-probe.
Comments suppressed due to low confidence (1)

src/Tools/dotnet-trace/CommandLine/Commands/CollectLinuxCommand.cs:268

  • The new try/catch introduces a scoping/compilation issue: supports, resolvedPid, resolvedName, and detectedRuntimeVersion are declared inside the try block but are used afterward (e.g., in BuildProcessSupportCsv(...) and the if (supports) block). This won’t compile. Consider either (1) declaring these variables before the try and assigning within it, or (2) moving BuildProcessSupportCsv and the subsequent if/else logic inside the try block.

Also, since ex isn’t used other than the filter, you can simplify by using separate catch (DiagnosticToolException) / catch (DiagnosticsClientException) blocks instead of catch (Exception ex) when ....

                        try
                        {
                            bool supports = ProcessSupportsUserEventsIpcCommand(pid, string.Empty, out int resolvedPid, out string resolvedName, out string detectedRuntimeVersion);
                        }
                        catch (Exception ex) when (ex is DiagnosticToolException or DiagnosticsClientException)
                        {
                            // Process may have exited between enumeration and probing — skip it.
                            continue;
                        }

                        BuildProcessSupportCsv(resolvedPid, resolvedName, supports, supportedCsv, unsupportedCsv);
                        if (supports)
                        {
                            supportedProcesses.AppendLine($"{resolvedPid} {resolvedName}");
                        }
                        else
                        {
                            unsupportedProcesses.AppendLine($"{resolvedPid} {resolvedName} - Detected runtime: '{detectedRuntimeVersion}'");
                        }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@hoyosjs hoyosjs force-pushed the juhoyosa/fix-flakey-test branch from cc64db7 to 9853085 Compare March 25, 2026 00:53
@hoyosjs hoyosjs merged commit 0a89e9f into dotnet:main Mar 25, 2026
19 checks passed
@hoyosjs hoyosjs deleted the juhoyosa/fix-flakey-test branch March 25, 2026 16:18
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.

Microsoft.Diagnostics.Tools.Trace.CollectLinuxCommandFunctionalTests.CollectLinuxCommand_Probe_Csv failing

3 participants