Skip to content

NETCore.Client: GetProcPublishedProcesses throws IOException on Linux when kernel thread is visible #5903

Closed

Description

@clutterloh

NETCore.Client: GetProcPublishedProcesses throws IOException on Linux when kernel thread is visible

DiagnosticsClient.GetPublishedProcesses() throws IOException ("No such process") on Linux when a kernel thread (e.g. PID 2 kthreadd) is visible in /proc. The new cross-namespace enumeration added in #5735 reads  /proc/{pid}/environ for every process, but kernel threads have no environment, so the read fails with ESRCH, surfaced by the runtime as a plain IOException that isn't caught. The exception aborts enumeration of all processes and propagates out of GetPublishedProcesses(), crashing the caller.

Kernel threads have no user address space (mm), so the kernel returns -ESRCH  for /proc/{pid}/environ even though the PID exists and Process.GetProcessById succeeds. Interop.ThrowExceptionForIoErrno has no mapping for ESRCH, so it produces a base IOException. PidIpcEndpoint.GetProcessTmpDir only catches DirectoryNotFoundException and UnauthorizedAccessException, so the IOException escapes; the per-/proc loop in DiagnosticsClient.GetProcPublishedProcesses has no guard, so one kernel thread fails the entire scan. Kernel threads are always present on a Linux host (and in pid: host /privileged containers), so this fires on essentially every call on every such host.

Minimal repro (Linux host or a privileged / pid: host container, .NET 9+ with the affected package):

using Microsoft.Diagnostics.NETCore.Client;
foreach (int pid in DiagnosticsClient.GetPublishedProcesses())
    System.Console.WriteLine(pid);
// Throws: System.IO.IOException: No such process : '/proc/2/environ'

Expected: GetPublishedProcesses() returns the set of discoverable diagnostic processes and silently skips entries whose /proc files can't be read (kernel threads, process-exit races, restricted entries).
Actual: It throws and returns nothing.

Configuration

  • Tool/package: Microsoft.Diagnostics.NETCore.Client (consumed by dotnet-trace/-counters/-stack/-dump; surfaced here via a hosted monitoring service calling  GetPublishedProcesses()).
  • OS: Linux (observed on a bare-metal/VM host). Also reproduces in privileged / pid: host containers. Not specific to a distro, depends only on host kernel threads being visible in the caller's PID namespace.
  • Architecture: x64 (not architecture-specific; this is /proc semantics).
  • Environment: the failing scenario is a host process / sidecar that can see other PID namespaces, i.e. exactly the cross-container case [DiagnosticsClient] Add cross-container support #5735 targets, plus any ordinary Linux host.
  • Not a self-contained published app (library reference).

Regression?

Yes. Introduced in #5735 ("[DiagnosticsClient] Add cross-container support"), first shipped in package  0.2.721401 . Versions ≤  0.2.652701  do not enumerate  /proc /read  environ  and are unaffected. The bug is still present in the latest published version (verified through  0.2.731901 ).

Other information

Observed stack trace:

IOException | No such process : '/proc/2/environ' |
   at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirError)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, UnixFileMode openPermissions, Int64& fileLength, UnixFileMode& filePermissions, Boolean failForSymlink, Boolean& wasSymlink, Func`4 createOpenException)
   at System.IO.File.OpenHandle(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
   at System.IO.File.ReadAllBytes(String path)
   at Microsoft.Diagnostics.NETCore.Client.PidIpcEndpoint.GetProcessTmpDir(Int32 hostPid, Boolean& environReadable)
   at Microsoft.Diagnostics.NETCore.Client.DiagnosticsClient.GetProcPublishedProcesses()
   at Microsoft.Diagnostics.NETCore.Client.DiagnosticsClient.GetPublishedProcesses()

Likely fix: have the best-effort /proc read helpers treat any unreadable entry as "skip and fall back" rather than only catching DirectoryNotFoundException / UnauthorizedAccessException. Specifically, broaden GetProcessTmpDir's catch (and TryGetNamespacePid's, which has the same gap for exit-race FileNotFoundException) to IOException, so a single unreadable /proc/{pid} entry can't abort discovery of all other processes.

Workaround: pin to 0.2.652701 or earlier (loses cross-container support from #5735).

Activity

  1. added
    bug
    on Jun 26, 2026
  2. added a commit that references this issue on Jun 29, 2026
    3a91cb2
  3. locked and limited conversation to collaborators on Jul 30, 2026
  4. added a commit that references this issue on Sep 30, 2026
    a931107
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions