From e224f0bdabd2d8d8591a8fb2566debe44d17a5ae Mon Sep 17 00:00:00 2001 From: Aikar Date: Wed, 10 Jun 2020 23:40:28 -0400 Subject: [PATCH] Fix issues with SIGTERM not shutting down gracefully - Fixes #3062 We had 2 issues. 1) Log4J2 Shutdown hook seemed to be causing issues as it shutdown logger while we still needed it 2) ServerShutdownThread needs to stay alive until server is shutdown to keep jvm open. It appears SIGINT is handled differently than SIGTERM, as SIGINT worked correctly. But this will make both methods work. --- .../0467-Improved-Watchdog-Support.patch | 57 ++++++++++++++----- ...Wait-for-Async-Tasks-during-shutdown.patch | 4 +- 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/Spigot-Server-Patches/0467-Improved-Watchdog-Support.patch b/Spigot-Server-Patches/0467-Improved-Watchdog-Support.patch index 0dbdf6d636..71f97b5370 100644 --- a/Spigot-Server-Patches/0467-Improved-Watchdog-Support.patch +++ b/Spigot-Server-Patches/0467-Improved-Watchdog-Support.patch @@ -67,7 +67,7 @@ index 3de19c998b749ccf74958c2412a8c9506457383e..c7dc8787cc3456c5540d6a00a6ff0515 throwable = throwable.getCause(); } diff --git a/src/main/java/net/minecraft/server/DedicatedServer.java b/src/main/java/net/minecraft/server/DedicatedServer.java -index 1ef7890da599d13e784861035e7891efcc4cd504..b07c49f1b48cc6dedd7c2057da0ec4f6f6d446e6 100644 +index 1ef7890da599d13e784861035e7891efcc4cd504..32cd645abb236b355f4f4f0f810e56342ee6cc06 100644 --- a/src/main/java/net/minecraft/server/DedicatedServer.java +++ b/src/main/java/net/minecraft/server/DedicatedServer.java @@ -299,7 +299,7 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer @@ -79,7 +79,15 @@ index 1ef7890da599d13e784861035e7891efcc4cd504..b07c49f1b48cc6dedd7c2057da0ec4f6 if (dedicatedserverproperties.announcePlayerAchievements != null) { ((GameRules.GameRuleBoolean) this.getGameRules().get(GameRules.ANNOUNCE_ADVANCEMENTS)).a(dedicatedserverproperties.announcePlayerAchievements, (MinecraftServer) this); } -@@ -750,7 +750,7 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer +@@ -422,6 +422,7 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer + //this.remoteStatusListener.b(); // Paper - don't wait for remote connections + } + ++ hasFullyShutdown = true; // Paper + System.exit(0); // CraftBukkit + } + +@@ -750,7 +751,7 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer @Override public void stop() { super.stop(); @@ -101,7 +109,7 @@ index cfe43e882e524b6ab3d9702e81269c97e6b75eba..2632c7c3ec77918be7979f2aa49209e5 } diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java -index c07339c87f8efff9c26aadc778cc3b16e170673f..d1a1c4a89d7148c58d1e60843f233f026a6d9f0e 100644 +index a0e33d42a158defc8b4a72de5d01b9395dca42eb..2c9ae5c46a39639fd9f842df23993a47b31c8585 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -144,6 +144,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant asList(String... params) { return Arrays.asList(params); diff --git a/src/main/java/org/bukkit/craftbukkit/util/ServerShutdownThread.java b/src/main/java/org/bukkit/craftbukkit/util/ServerShutdownThread.java -index 449e99d1b673870ed6892f6ab2c715a2db35c35d..899a525209cfe047ce57e758c6328a130f916dc6 100644 +index 449e99d1b673870ed6892f6ab2c715a2db35c35d..c7ed6e0f8a989cec97700df2b15198c9c481c549 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/ServerShutdownThread.java +++ b/src/main/java/org/bukkit/craftbukkit/util/ServerShutdownThread.java -@@ -12,12 +12,25 @@ public class ServerShutdownThread extends Thread { +@@ -12,12 +12,27 @@ public class ServerShutdownThread extends Thread { @Override public void run() { try { @@ -431,6 +447,7 @@ index 449e99d1b673870ed6892f6ab2c715a2db35c35d..899a525209cfe047ce57e758c6328a13 + Thread.sleep(100); + } + if (server.hasStopped()) { ++ while (!server.hasFullyShutdown) Thread.sleep(1000); + return; + } + // Looks stalled, close async @@ -438,6 +455,7 @@ index 449e99d1b673870ed6892f6ab2c715a2db35c35d..899a525209cfe047ce57e758c6328a13 org.spigotmc.AsyncCatcher.shuttingDown = true; // Paper + server.forceTicks = true; server.close(); ++ while (!server.hasFullyShutdown) Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + // Paper end @@ -534,3 +552,14 @@ index 5bdcdcf9e85b73086722783bff26321d03382bb9..513c1041c34ebb3ac1775674a3f45266 } break; } // Paper end +diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml +index 476f4a5cbe664ddd05474cb88553018bd334a5b8..8af159abd3d0cc94cf155fec5b384c42f69551bf 100644 +--- a/src/main/resources/log4j2.xml ++++ b/src/main/resources/log4j2.xml +@@ -1,5 +1,5 @@ + +- ++ + + + diff --git a/Spigot-Server-Patches/0516-Wait-for-Async-Tasks-during-shutdown.patch b/Spigot-Server-Patches/0516-Wait-for-Async-Tasks-during-shutdown.patch index 90826ec509..b7b12e7797 100644 --- a/Spigot-Server-Patches/0516-Wait-for-Async-Tasks-during-shutdown.patch +++ b/Spigot-Server-Patches/0516-Wait-for-Async-Tasks-during-shutdown.patch @@ -10,10 +10,10 @@ Adds a 5 second grace period for any async tasks to finish and warns if any are still running after that delay just as reload does. diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java -index a70492f617408597230a39e49fa311822171851d..a03dc230521673a21872d70836903a2c2d15220e 100644 +index 2c9ae5c46a39639fd9f842df23993a47b31c8585..4ab6579032043f570c20befa7fef8931babd2355 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java -@@ -746,6 +746,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant