From e64a6329985732c8c4c62a7bd492ca7b871d1bd7 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Sun, 2 Feb 2025 13:07:28 -0800 Subject: [PATCH] fix: Moves snapshot request synchronously (#2105) --- Projects/Server/Main.cs | 3 +-- Projects/Server/World/World.cs | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Projects/Server/Main.cs b/Projects/Server/Main.cs index 44e84f0fc..d25827f6a 100644 --- a/Projects/Server/Main.cs +++ b/Projects/Server/Main.cs @@ -517,11 +517,10 @@ public static void RunEventLoop() DoKill(_restartOnKill); } - // This is generally called from background threads during Preserialize internal static void RequestSnapshot(string snapshotPath) { _snapshotPath = snapshotPath; - _performSnapshot = true; // Set this after the path so race conditions do not occur + _performSnapshot = true; } public static void VerifySerialization() diff --git a/Projects/Server/World/World.cs b/Projects/Server/World/World.cs index 6a11c4f82..14a5ba31f 100644 --- a/Projects/Server/World/World.cs +++ b/Projects/Server/World/World.cs @@ -279,8 +279,6 @@ public static void Save() private static void Preserialize(object state) { - var tempPath = PathUtility.EnsureRandomPath(_tempSavePath); - try { // Allocate the heaps for the GC @@ -290,7 +288,9 @@ private static void Preserialize(object state) } WakeSerializationThreads(); - Core.RequestSnapshot(tempPath); + + // Execute this synchronously so we don't have a race condition + Core.LoopContext.Post(() => Core.RequestSnapshot(PathUtility.EnsureRandomPath(_tempSavePath))); } catch (Exception ex) {