Skip to content

fix: ping CTS leak, Event Log UI-thread block, AMD/Intel GPU name#819

Merged
laurentiu021 merged 1 commit into
mainfrom
fix/r3b-p1-thread-resource-safety
Jun 8, 2026
Merged

fix: ping CTS leak, Event Log UI-thread block, AMD/Intel GPU name#819
laurentiu021 merged 1 commit into
mainfrom
fix/r3b-p1-thread-resource-safety

Conversation

@laurentiu021

Copy link
Copy Markdown
Owner

Round 3 (batch 2) — thread/resource safety.

Ping monitor leaked its CancellationTokenSource

PingMonitorService.Stop set _cts = null without disposing it whenever the 1.5s loop wait timed out (loop still winding down), leaking the CTS. It now captures the CTS locally and disposes it once the loop actually finishes — immediately if complete, otherwise via a ContinueWith.

System Logs froze the UI while reading the Event Log

EventLogService.ReadAsync ran the blocking EventLogReader.ReadEvent() COM call on the caller's (UI) thread; await Task.Yield() only released it momentarily per 200 rows, so large logs still froze the app. Each read now runs on the thread pool via Task.Run.

Dashboard GPU only worked for NVIDIA

UpdateGpuUsage queried only NvAPI, so AMD/Intel users saw no GPU. Added a Win32_VideoController (WMI) fallback for the adapter name. Live usage % stays NVIDIA-only (vendor-specific APIs).

Note

StartupViewModel's cross-thread mutation (also in the audit) was already fixed in #585 — verified, no change needed.

Tests & regression

  • PingMonitorServiceLifecycleTests: start/stop, stop-without-start, repeated cycles, dispose-after-start, double-start idempotency.
  • Full-solution build clean (main + Tests + IntegrationTests + UITests). Version 1.20.4.

Round 3 (batch 2) — thread/resource safety:

- PingMonitorService.Stop dropped the CTS reference (set _cts=null) without
  disposing it whenever the 1.5s loop wait timed out, leaking the CTS. It now
  captures the CTS locally and disposes it once the loop finishes — immediately
  if already complete, else via a ContinueWith.
- EventLogService.ReadAsync ran the blocking EventLogReader.ReadEvent() COM call
  on the caller's UI thread (await Task.Yield only released it momentarily), so
  large logs froze the UI. Each read now runs on the thread pool via Task.Run.
- DashboardViewModel.UpdateGpuUsage only queried NVIDIA via NvAPI, so AMD/Intel
  users saw no GPU at all. Added a Win32_VideoController (WMI) fallback for the
  adapter name (usage % stays NVIDIA-only — vendor-specific APIs).

StartupViewModel's cross-thread mutation (also flagged in the audit) was already
fixed in #585, verified.

Test: PingMonitorServiceLifecycleTests covers start/stop/dispose/double-start.
// thread so enumerating large logs never blocks the UI thread the
// caller awaits on. (await Task.Yield() alone did not move the work
// off the UI thread — it only released it momentarily per 200 rows.)
EventRecord? rec;
@laurentiu021 laurentiu021 merged commit 734fdb9 into main Jun 8, 2026
4 checks passed
@laurentiu021 laurentiu021 deleted the fix/r3b-p1-thread-resource-safety branch June 8, 2026 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants