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
This commit is contained in:
Kamron Batman 2025-02-02 12:05:40 -08:00 committed by GitHub
parent 019672b026
commit 717a1a062e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View file

@ -517,10 +517,11 @@ public static class Core
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()

View file

@ -324,6 +324,11 @@ public static class World
{
_serializationStart = Core.Now;
if (string.IsNullOrEmpty(snapshotPath))
{
throw new ArgumentException("Snapshot path cannot be null or empty", nameof(snapshotPath));
}
Persistence.SerializeAll();
PauseSerializationThreads();
EventSink.InvokeWorldSave();