Skip to content

Commit

Permalink
fix: Fixes race condition with world save snapshot request (#2104)
Browse files Browse the repository at this point in the history
### 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
  • Loading branch information
kamronbatman authored Feb 2, 2025
1 parent 019672b commit 717a1a0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Projects/Server/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions Projects/Server/World/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 717a1a0

Please sign in to comment.