Skip to content

[release/stable] Backport process discovery, gcdump, and trace updates - #6078

Merged
hoyosjs merged 5 commits into
dotnet:release/stablefrom
hoyosjs:juhoyosa/stable-tool-backports
Sep 30, 2026
Merged

hoyosjs merged 5 commits into
dotnet:release/stablefrom
hoyosjs:juhoyosa/stable-tool-backports

Conversation

@hoyosjs

@hoyosjs hoyosjs commented Sep 29, 2026

Copy link
Copy Markdown
Member

Backport the Linux /proc process-discovery fix for #6040 and the gcdump and dotnet-trace changes needed on release/stable:

Non-lossy buffering requires a .NET 11+ target runtime; gcdump warns and falls back to lossy collection for older runtimes. Linux-specific behavior has not been exercised locally on Windows.

clutterloh and others added 5 commits September 29, 2026 15:30
…ocess discovery (dotnet#5904)

Fixes dotnet#5903

## Problem

`DiagnosticsClient.GetProcPublishedProcesses` enumerates `/proc` to
discover diagnostic-capable processes. Two best-effort per-process read
helpers only caught `DirectoryNotFoundException` /
`UnauthorizedAccessException`:

- `GetProcessTmpDir` reads `/proc/{pid}/environ`. Kernel threads (e.g.
`kthreadd` at PID 2) have no user address space, so the kernel returns
`-ESRCH` and the runtime surfaces a plain `IOException` (`"No such
process"`). This escaped the catch and aborted the entire enumeration,
crashing `GetPublishedProcesses` on **every** Linux host, since kernel
threads are always present.
- `TryGetNamespacePid` reads `/proc/{pid}/status` and had the same
too-narrow catch, so a process-exit race or a `hidepid`-restricted
process could throw.

This was introduced by dotnet#5735 (first shipped in `0.2.721401`) and is
still present in the latest package.

## Fix

- Broaden both catches to `IOException`, which subsumes the prior
`DirectoryNotFoundException` / `FileNotFoundException` exit-race cases.
- Add a `UnauthorizedAccessException` catch to `TryGetNamespacePid`
(parity with `GetProcessTmpDir`).

Both helpers are best-effort, so they now consistently skip an
unreadable entry rather than throwing and aborting discovery. The
enumeration loop is unchanged.

## Tests

Adds two Linux-gated (`[ConditionalFact]`) tests in
`PidIpcEndpointTests`:
- `GetProcessTmpDir_KernelThread_DoesNotThrow` — finds a process whose
`environ` throws `IOException` (a kernel thread) and asserts the
temp-dir fallback is returned. Skips if no such process is visible (e.g.
inside a container with its own PID namespace).
- `TryGetNamespacePid_NonExistentPid_DoesNotThrow` — a non-existent PID
returns `false` rather than throwing.

---------

Co-authored-by: Copilot Autofix powered by AI <[email protected]>

(cherry picked from commit 3a91cb2)

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 1bf039ff-37e1-40b6-af8c-125192e61855
…t#5886)

Diagnostics counterpart to dotnet/runtime#129457
for fixing dotnet#2404

This PR proposes a new CollectTracing command `CollectTracing6` that
exposes a new `sessionBufferMode` configuration option to specify how an
IPC Streaming EventPipe Session using buffers should handle events when
buffers are full.

0 - Drop (default, pre-existing behavior)
1 - Block (non-lossy, parks producer threads until buffer space is
available)

Additionally, this PR introduces serializing for CollectTracing5
(non-UserEvents) and CollectTracing6, and adds a new `--non-lossy`
option to `dotnet-gcdump collect` to leverage the new non-lossy mode.

---------

Co-authored-by: Copilot <[email protected]>

(cherry picked from commit 7e8e386)

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 1bf039ff-37e1-40b6-af8c-125192e61855
Fixes dotnet#6048

## Summary

- Keep EventPipe completion state local to each live collection and file
conversion.
- Report success only after heap graph conversion completes.
- Document that the live collection log writer must support concurrent
writes.
- Add regression coverage for a post-GCStop logging failure returning
false.

## Root cause

The failure in dotnet#6048 has two parts. Steeltoe calls
`EventPipeDotNetHeapDumper` directly and supplies a plain
`StreamWriter`, while the method logs concurrently from the EventPipe
reader and session stop tasks. That caller-provided writer is not
thread-safe, which explains the torn log line and `StreamWriter.Flush`
exception. The shipped CLI uses synchronized `Console.Out`, so
diagnostics continues to require callers of the direct API to provide a
writer that supports concurrent writes.

After the logging exception, graph conversion is skipped. The previous
implementation nevertheless returned the process-wide `dumpComplete`
flag set when `GCStop` was observed. The caller therefore received
`true` for an unconverted graph and failed with `RootIndex not set`. The
process-wide flags also allowed separate or concurrent operations to
affect each other.

This change gives each operation its own completion state and separates
GC completion from operation success. `true` is returned only after
`ConvertHeapDataToGraph()` completes.

Steeltoe must separately use a synchronized writer for direct in-process
gcdump calls.

## Reproduction

A real self-gcdump test injects a logging failure after `GCStop` and
verifies that the operation returns `false` because graph conversion did
not complete. The targeted test passes in Debug and Release.

---------

Copilot-Session: 432587bf-ff0a-4257-ad8a-fc58a1a8c6a9

(cherry picked from commit 2a16a62)

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 1bf039ff-37e1-40b6-af8c-125192e61855
(cherry picked from commit 1fb4a0b)

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 1bf039ff-37e1-40b6-af8c-125192e61855
…dotnet#6071)

Bump `record-trace` to get unwind improvements and other fixes.

Newer `record-trace` versions also have a [`max-memory`
option](microsoft/one-collect#291) so wire that
up too. It stops collection when the memory of the collecting process,
`dotnet-trace` in this case, exceeds the given limit.

I'm open to suggestions on the option description. For reference, the
description in record-trace is

```
Stop collecting once this process uses the specified amount of memory, in megabytes
```

Example output when the memory limit is reached:

```
root [ /src ]# ./dotnet-trace collect-linux --duration '00:00:20' --max-memory 100
No providers, profiles, ClrEvents, or PerfEvents were specified, defaulting to trace profiles 'dotnet-common' + 'cpu-sampling'.

Provider Name                           Keywords            Level               Enabled By
Microsoft-Windows-DotNETRuntime         0x000000100003801D  Informational(4)    --profile

Linux Perf Events                                                               Enabled By
cpu-sampling                                                                    --profile

Output File    : /src/trace_20260910_004355.nettrace

[00:00:00:01]   Recording trace.
Press <Enter> or <Ctrl+C> to exit...
Memory limit reached.
Recording stopped.
Resolving symbols.
Finished recording trace.
Trace written to /src/trace_20260910_004355.nettrace
```

(cherry picked from commit 2e2793f)

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 1bf039ff-37e1-40b6-af8c-125192e61855
@hoyosjs
hoyosjs marked this pull request as ready for review September 30, 2026 00:32
@hoyosjs
hoyosjs requested a review from a team as a code owner September 30, 2026 00:32
@hoyosjs

hoyosjs commented Sep 30, 2026

Copy link
Copy Markdown
Member Author

Preexisting mac bug in event pipeline testing - other timeout is unrelated to diagnostics.

@hoyosjs
hoyosjs merged commit d24af9f into dotnet:release/stable Sep 30, 2026
21 of 26 checks passed
@hoyosjs
hoyosjs deleted the juhoyosa/stable-tool-backports branch September 30, 2026 02:23
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 30, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants