Skip to content

Fix CancellationTokenSource leak in ViewModels#3448

Merged
mergify[bot] merged 2 commits into
mainfrom
fix/cts-dispose-leak
May 25, 2026
Merged

Fix CancellationTokenSource leak in ViewModels#3448
mergify[bot] merged 2 commits into
mainfrom
fix/cts-dispose-leak

Conversation

@BornToBeRoot
Copy link
Copy Markdown
Owner

Summary

  • Dispose the previous CancellationTokenSource before overwriting it in IPScannerViewModel, PortScannerViewModel, TracerouteViewModel, PingMonitorViewModel, PingMonitorHostViewModel, and SNMPViewModel
  • Each Start() call created a new CancellationTokenSource without disposing the previous instance, leaking the underlying WaitHandle on every run
  • Fix is a single _cancellationTokenSource?.Dispose() line before each reassignment — safe because CanExecute guards ensure IsRunning is false before Start() is called again

Test plan

  • Start and stop IP Scanner multiple times — no leak
  • Start and stop Port Scanner multiple times — no leak
  • Start and stop Traceroute multiple times — no leak
  • Start and stop Ping Monitor multiple times — no leak
  • Start and stop SNMP multiple times — no leak

🤖 Generated with Claude Code

Dispose the previous CancellationTokenSource before overwriting it in
IPScanner, PortScanner, Traceroute, PingMonitor, PingMonitorHost and SNMP.
Each Start() created a new instance without disposing the old one, leaking
the WaitHandle allocated by CancellationTokenSource on every run.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 25, 2026 15:59
@github-actions github-actions Bot added this to the next-release milestone May 25, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a resource leak in several WPF ViewModels by disposing the previous CancellationTokenSource before creating a new one on each run, preventing WaitHandle accumulation across repeated Start/Stop cycles.

Changes:

  • Added _cancellationTokenSource?.Dispose(); immediately before reassigning a new CancellationTokenSource in multiple ViewModels.
  • Applied the same pattern consistently across scanner/monitor/traceroute/SNMP workflows.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
Source/NETworkManager/ViewModels/TracerouteViewModel.cs Dispose previous CTS before starting a new traceroute run.
Source/NETworkManager/ViewModels/SNMPViewModel.cs Dispose previous CTS before starting a new SNMP operation.
Source/NETworkManager/ViewModels/PortScannerViewModel.cs Dispose previous CTS before starting a new port scan.
Source/NETworkManager/ViewModels/PingMonitorViewModel.cs Dispose previous CTS before starting ping monitoring for a host.
Source/NETworkManager/ViewModels/PingMonitorHostViewModel.cs Dispose previous CTS before starting host-resolution/add workflow in Ping Monitor Host view.
Source/NETworkManager/ViewModels/IPScannerViewModel.cs Dispose previous CTS before starting a new IP scan.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +505 to 507
_cancellationTokenSource?.Dispose();
_cancellationTokenSource = new CancellationTokenSource();

@mergify mergify Bot merged commit 175665c into main May 25, 2026
5 checks passed
@mergify mergify Bot deleted the fix/cts-dispose-leak branch May 25, 2026 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants