From 0d19a5ff99f393c4d86ec2c2f9c0b4576c4ac4fa Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Thu, 14 Jul 2022 11:27:29 -0700 Subject: [PATCH] fix: Do not use unsafe work queue for auto archiving (#1116) --- Projects/Server/Timer/Timer.Pool.cs | 3 ++- Projects/UOContent/World Saves/AutoArchive.cs | 16 +++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Projects/Server/Timer/Timer.Pool.cs b/Projects/Server/Timer/Timer.Pool.cs index 79f467b86..b48fbb131 100644 --- a/Projects/Server/Timer/Timer.Pool.cs +++ b/Projects/Server/Timer/Timer.Pool.cs @@ -119,7 +119,8 @@ public partial class Timer { RefillPool(amountToRefill, out var head, out var tail); return (head, tail); - } + }, + Core.ClosingTokenSource.Token ); ReturnToPool(amountToRefill, headTimer, tailTimer); diff --git a/Projects/UOContent/World Saves/AutoArchive.cs b/Projects/UOContent/World Saves/AutoArchive.cs index b7cf2d50b..837c826e1 100755 --- a/Projects/UOContent/World Saves/AutoArchive.cs +++ b/Projects/UOContent/World Saves/AutoArchive.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using System.IO; using System.Runtime.CompilerServices; using System.Threading; +using System.Threading.Tasks; using Microsoft.Toolkit.HighPerformance; using Server.Compression; using Server.Logging; @@ -218,7 +219,7 @@ namespace Server.Saves } } - public static void AutoArchiveLocally() + public static async void AutoArchiveLocally() { var date = Core.Now; @@ -232,22 +233,22 @@ namespace Server.Saves return; } - ThreadPool.UnsafeQueueUserWorkItem( - _ => + ThreadPool.QueueUserWorkItem( + now => { - if (date >= _nextHourlyArchive) + if (now >= _nextHourlyArchive) { Rollup(ArchivePeriod.Hourly); _nextHourlyArchive = _nextHourlyArchive.AddHours(1); } - if (date >= _nextDailyArchive) + if (now >= _nextDailyArchive) { Rollup(ArchivePeriod.Daily); _nextDailyArchive = _nextDailyArchive.AddDays(1); } - if (date >= _nextMonthlyArchive) + if (now >= _nextMonthlyArchive) { Rollup(ArchivePeriod.Monthly); _nextMonthlyArchive = _nextMonthlyArchive.AddMonths(1); @@ -256,7 +257,8 @@ namespace Server.Saves Prune?.Invoke(); _isArchiving = 0; }, - null + date, + false ); }