镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Fall back to the name and start time when MainModule is null [patch] - #215

Merged
matt-edmondson merged 1 commit into
mainfrom
claude/sai-214-null-mainmodule
Nov 10, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
claude/sai-214-null-mainmodule

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Summary

On Linux, .NET reads MainModule from /proc/<pid>/maps. Another user can't read that file, so MainModule comes back null instead of throwing Win32Exception. The MainModule != null clause in IsStoredProcessRunning then answered "not running" without ever reaching the name-and-start-time fallback. A second instance could launch next to one run by another user, for example under sudo -E, or when hidepid is set.

  • The PID and process-name checks now run first. The main module is read once. If it is null, the method takes the same IsStoredProcessRunningByName fallback that a Win32Exception already takes.
  • The module lookup goes through an internal overload, IsStoredProcessRunning(ProcessInfo, Func<Process, string?>), so that path can be tested without a second user account. The production overload passes p => p.MainModule?.FileName.
  • The Windows Win32Exception path is unchanged. A throw from the lookup is still caught by the existing handler.

Tests

Four new tests run against a live helper process:

  • Null module, with matching name and start time: running. This one fails without the fix.
  • Null module with a different start time: not running. The fallback still guards against a recycled PID.
  • Lookup throws Win32Exception: running, same as today.
  • Readable module that differs: not running.

dotnet test: 46 passed, 0 failed.

Fixes #214


Generated by Claude Code

On Linux another user's /proc/<pid>/maps is unreadable, so MainModule
comes back null instead of throwing Win32Exception. The null check made
IsStoredProcessRunning answer "not running", so a second instance
launched alongside one run by another user. A null module now takes the
same fallback as access denied. The lookup goes through a seam so the
path is testable.

Fixes #214

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW5qLcDVLnunDHexs7L
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants