From 717a1a062e99b7084f6ae7f1a66ffc0c1449e2f2 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Sun, 2 Feb 2025 12:05:40 -0800 Subject: [PATCH] fix: Fixes race condition with world save snapshot request (#2104) ### Summary * Fixes a race condition where the snapshot path isn't between the request snapshot being set on a background thread, and the main loop consuming that flag. Closes #2102 --- Projects/Server/Main.cs | 3 ++- Projects/Server/World/World.cs | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Projects/Server/Main.cs b/Projects/Server/Main.cs index 535327cbe8..44e84f0fc6 100644 --- a/Projects/Server/Main.cs +++ b/Projects/Server/Main.cs @@ -517,10 +517,11 @@ public static void RunEventLoop() DoKill(_restartOnKill); } + // This is generally called from background threads during Preserialize internal static void RequestSnapshot(string snapshotPath) { - _performSnapshot = true; _snapshotPath = snapshotPath; + _performSnapshot = true; // Set this after the path so race conditions do not occur } public static void VerifySerialization() diff --git a/Projects/Server/World/World.cs b/Projects/Server/World/World.cs index 234c76d0b5..6a11c4f82d 100644 --- a/Projects/Server/World/World.cs +++ b/Projects/Server/World/World.cs @@ -324,6 +324,11 @@ internal static void Snapshot(string snapshotPath) { _serializationStart = Core.Now; + if (string.IsNullOrEmpty(snapshotPath)) + { + throw new ArgumentException("Snapshot path cannot be null or empty", nameof(snapshotPath)); + } + Persistence.SerializeAll(); PauseSerializationThreads(); EventSink.InvokeWorldSave();