Skip to content

Read the process list fresh in Kill and TryGetProcessInfo - #777

Closed
SimonCropp wants to merge 1 commit into
mainfrom
fix-process-cleanup-stale-list
Closed

Read the process list fresh in Kill and TryGetProcessInfo#777
SimonCropp wants to merge 1 commit into
mainfrom
fix-process-cleanup-stale-list

Conversation

@SimonCropp

Copy link
Copy Markdown
Member

ProcessCleanup filled its list once, in the static constructor, and Refresh had no other caller in the library. So every question about what is running was answered from a snapshot taken the first time anything touched DiffEngine.

Inside one process that means a tool launched after first use is invisible for the rest of that process:

  • Launch then Kill for the same pair logs "No matching commands" and leaves the tool open.
  • A relaunch never sees the running instance, so a second window opens and another MaxInstance slot goes with it.
  • An AutoRefresh tool is relaunched instead of being reused and refreshed.
  • A PID from the startup snapshot may belong to something else entirely by the time Kill terminates it.

Refresh at the top of Kill and TryGetProcessInfo. It costs about 14ms on Windows now that CandidateExeNames restricts the command line reads to resolved diff tool images, against a call that is about to start or kill a process.

DiffRunnerTests could not have caught this: every test polls through WaitForRunning, which calls Refresh itself, and FakeDiffTool exits on its own after five seconds, so a kill that matched nothing still looked like a kill that worked. The new test refreshes once while the tool is not running, launches, and then asks only the cached query - inside the five seconds, so a pass means it saw the process rather than outlived it.

ProcessCleanup filled its list once, in the static constructor, and Refresh had
no other caller in the library. So every question about what is running was
answered from a snapshot taken the first time anything touched DiffEngine.

Inside one process that means a tool launched after first use is invisible for
the rest of that process:

 - Launch then Kill for the same pair logs "No matching commands" and leaves the
   tool open.
 - A relaunch never sees the running instance, so a second window opens and
   another MaxInstance slot goes with it.
 - An AutoRefresh tool is relaunched instead of being reused and refreshed.
 - A PID from the startup snapshot may belong to something else entirely by the
   time Kill terminates it.

Refresh at the top of Kill and TryGetProcessInfo. It costs about 14ms on
Windows now that CandidateExeNames restricts the command line reads to resolved
diff tool images, against a call that is about to start or kill a process.

DiffRunnerTests could not have caught this: every test polls through
WaitForRunning, which calls Refresh itself, and FakeDiffTool exits on its own
after five seconds, so a kill that matched nothing still looked like a kill that
worked. The new test refreshes once while the tool is not running, launches, and
then asks only the cached query - inside the five seconds, so a pass means it
saw the process rather than outlived it.
@SimonCropp SimonCropp closed this Aug 21, 2026
@SimonCropp
SimonCropp deleted the fix-process-cleanup-stale-list branch August 21, 2026 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant