From 01b6bc66dbfa7a55420579724f7a84b45fecab94 Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Sat, 5 Mar 2022 17:29:47 -0800 Subject: [PATCH] Fix save problems on shutdown - Save level.dat first, in case the shutdown is killed later - Force run minecraftserver tasks and the chunk source tasks while waiting for the chunk system to empty, as there's simply too much trash that could prevent them from executing during the chunk source tick (i.e "time left in tick" logic). --- .../Fix-deadlock-on-watchdog-crash.patch | 21 ------- .../Fix-save-problems-on-shutdown.patch | 59 +++++++++++++++++++ 2 files changed, 59 insertions(+), 21 deletions(-) delete mode 100644 patches/server/Fix-deadlock-on-watchdog-crash.patch create mode 100644 patches/server/Fix-save-problems-on-shutdown.patch diff --git a/patches/server/Fix-deadlock-on-watchdog-crash.patch b/patches/server/Fix-deadlock-on-watchdog-crash.patch deleted file mode 100644 index d439715e9b..0000000000 --- a/patches/server/Fix-deadlock-on-watchdog-crash.patch +++ /dev/null @@ -1,21 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> -Date: Fri, 4 Mar 2022 00:12:49 -0700 -Subject: [PATCH] Fix deadlock on watchdog crash - -The watchdog thread sets MinecraftServer#forceTicks to true which will -cause waitUntilNextTick to hang when the task queue is drained. - -diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java -index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 ---- a/src/main/java/net/minecraft/server/MinecraftServer.java -+++ b/src/main/java/net/minecraft/server/MinecraftServer.java -@@ -0,0 +0,0 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop !this.canSleepForTickNoOversleep() || this.getPendingTasksCount() == 0); // Paper - based on waitUntilNextTick - } - - this.saveAllChunks(false, true, false); diff --git a/patches/server/Fix-save-problems-on-shutdown.patch b/patches/server/Fix-save-problems-on-shutdown.patch new file mode 100644 index 0000000000..5487626aba --- /dev/null +++ b/patches/server/Fix-save-problems-on-shutdown.patch @@ -0,0 +1,59 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Spottedleaf +Date: Sat, 5 Mar 2022 17:12:52 -0800 +Subject: [PATCH] Fix save problems on shutdown + +- Save level.dat first, in case the shutdown is killed later +- Force run minecraftserver tasks and the chunk source tasks + while waiting for the chunk system to empty, as there's simply + too much trash that could prevent them from executing during + the chunk source tick (i.e "time left in tick" logic). + +diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/server/MinecraftServer.java ++++ b/src/main/java/net/minecraft/server/MinecraftServer.java +@@ -0,0 +0,0 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop { + return worldserver1.getChunkSource().chunkMap.hasWork(); + })) { +@@ -0,0 +0,0 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop { + return true; + }, false); ++ while (worldserver.getChunkSource().pollTask()); // Paper - drain tasks + } + +- this.waitUntilNextTick(); ++ while (this.pollTask()); // Paper - drain tasks + } + + this.saveAllChunks(false, true, false); +diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/server/level/ServerLevel.java ++++ b/src/main/java/net/minecraft/server/level/ServerLevel.java +@@ -0,0 +0,0 @@ public class ServerLevel extends Level implements WorldGenLevel { + } + + } ++ // Paper start ++ this.saveLevelDat(); ++ } + ++ public void saveLevelDat() { ++ this.saveLevelData(); ++ // Paper end + // CraftBukkit start - moved from MinecraftServer.saveChunks + ServerLevel worldserver1 = this; +