Fix ProcessLoader stale PID validation against kernel process table #102

Merged
LotP merged 1 commit from Babib3l/Ryubing:process-loader-stale-pid into master 2026-05-16 01:11:07 +00:00
Contributor

This PR adresses the following issue : ProcessLoader.ActiveApplication could return invalid results when _latestPid pointed to a process that no longer existed in the kernel's process table. The original exception path was commented out and bypassed (by sh0inx?) with GetValueOrDefault to prevent UI lockups, but this only resolved the symptoms without fixing the root cause.

This was due to sevral factors :

  • _latestPid was never reset or validated against the actual process state
  • ProcessLoader maintained its own _processesByPid dictionary separate from the kernel's KernelContext.Processes
  • No cleanups happened when processes exited or were terminated
  • ProcessLoader state could drift out of sync with the kernel process table

Solution/Fixes

  • Validate _latestPid against the kernel process table before returning ActiveApplication
  • Check process state (Exited/Exiting) and automatically clear stale references
  • Add thread-safe cleanup methods (ClearProcess, ClearAllProcesses)
  • Integrate ClearAllProcesses into Switch.Dispose for proper shutdown cleanup
  • Add warning logs when stale PID is detected and cleared for debugging

Code Changes:

  • ProcessLoader.cs: Add _pidLock, update ActiveApplication with validation, add cleanup methods
  • Switch.cs: Call Processes.ClearAllProcesses() in Dispose()
This PR adresses the following issue : `ProcessLoader.ActiveApplication` could return invalid results when `_latestPid` pointed to a process that no longer existed in the kernel's process table. The original exception path was commented out and bypassed (by sh0inx?) with `GetValueOrDefault` to prevent UI lockups, but this only resolved the symptoms without fixing the root cause. This was due to sevral factors : - `_latestPid` was never reset or validated against the actual process state - ProcessLoader maintained its own `_processesByPid` dictionary separate from the kernel's `KernelContext.Processes` - No cleanups happened when processes exited or were terminated - ProcessLoader state could drift out of sync with the kernel process table **Solution/Fixes** - Validate` _latestPid` against the kernel process table before returning `ActiveApplication` - Check process state (Exited/Exiting) and automatically clear stale references - Add thread-safe cleanup methods (`ClearProcess`, `ClearAllProcesses`) - Integrate `ClearAllProcesses` into Switch.Dispose for proper shutdown cleanup - Add warning logs when stale PID is detected and cleared for debugging **Code Changes**: - `ProcessLoader.cs`: Add `_pidLock`, update `ActiveApplication` with validation, add cleanup methods - `Switch.cs`: Call `Processes.ClearAllProcesses()` in Dispose()
Fix ProcessLoader stale PID validation
All checks were successful
Pull Request Triage / triage (pull_request_target) Successful in 18s
Build PR / linux-arm64 (Release) (pull_request) Successful in 6m10s
Build PR / win-x64 (Release) (pull_request) Successful in 8m55s
Build PR / macOS Universal (Release) (pull_request) Successful in 8m51s
Build PR / linux-x64 (Release) (pull_request) Successful in 9m16s
562dc9f82e
Validate _latestPid against kernel's process table and clear stale state
when detected. Add thread-safe cleanup methods and integrate into shutdown.
LotP merged commit e756ad4556 into master 2026-05-16 01:11:07 +00:00
Ghost added this to the 1.4.0 milestone 2026-06-27 17:15:30 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
projects/Ryubing!102
No description provided.