From 493a44d4439ac0eab7e17fa7374de7cf2fc5b070 Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sat, 26 Oct 2024 17:29:48 +0530 Subject: [PATCH] StatsManager: Added missing dispose call for cleanup timer. Updated MaxStatFileDays property to do validation and control cleanup timer. --- DnsServerCore/Dns/StatsManager.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/DnsServerCore/Dns/StatsManager.cs b/DnsServerCore/Dns/StatsManager.cs index 8b180e7f..6dee527c 100644 --- a/DnsServerCore/Dns/StatsManager.cs +++ b/DnsServerCore/Dns/StatsManager.cs @@ -264,8 +264,8 @@ namespace DnsServerCore.Dns if (disposing) { - if (_maintenanceTimer != null) - _maintenanceTimer.Dispose(); + _maintenanceTimer?.Dispose(); + _statsCleanupTimer?.Dispose(); //do last maintenance DoMaintenance(); @@ -1253,7 +1253,18 @@ namespace DnsServerCore.Dns public int MaxStatFileDays { get { return _maxStatFileDays; } - set { _maxStatFileDays = value; } + set + { + if (value < 0) + throw new ArgumentOutOfRangeException(nameof(MaxStatFileDays), "MaxStatFileDays must be greater than or equal to 0."); + + _maxStatFileDays = value; + + if (_maxStatFileDays == 0) + _statsCleanupTimer.Change(Timeout.Infinite, Timeout.Infinite); + else + _statsCleanupTimer.Change(STATS_CLEANUP_TIMER_INITIAL_INTERVAL, STATS_CLEANUP_TIMER_PERIODIC_INTERVAL); + } } #endregion