From 54e5a2e4dace02d7f246913be14be52ee8039628 Mon Sep 17 00:00:00 2001 From: Zach Brown <1254957+zachbr@users.noreply.github.com> Date: Sat, 13 May 2017 05:51:09 -0500 Subject: [PATCH] Publicly execute the main thread at dawn GH-684 Better handles most true deadlock situations --- .../Expose-server-CommandMap.patch | 4 +-- ...le-async-calls-to-restart-the-server.patch | 30 +++++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/Spigot-API-Patches/Expose-server-CommandMap.patch b/Spigot-API-Patches/Expose-server-CommandMap.patch index e091228532..f9afabb721 100644 --- a/Spigot-API-Patches/Expose-server-CommandMap.patch +++ b/Spigot-API-Patches/Expose-server-CommandMap.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Expose server CommandMap diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java -index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +index 3b16953a..07077ec4 100644 --- a/src/main/java/org/bukkit/Bukkit.java +++ b/src/main/java/org/bukkit/Bukkit.java @@ -0,0 +0,0 @@ import org.bukkit.boss.BarColor; @@ -39,7 +39,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 { return server.spigot(); diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java -index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +index a4e68943..4463ab33 100644 --- a/src/main/java/org/bukkit/Server.java +++ b/src/main/java/org/bukkit/Server.java @@ -0,0 +0,0 @@ import org.bukkit.boss.BarColor; diff --git a/Spigot-Server-Patches/Properly-handle-async-calls-to-restart-the-server.patch b/Spigot-Server-Patches/Properly-handle-async-calls-to-restart-the-server.patch index 64f66fc4de..d6bb697698 100644 --- a/Spigot-Server-Patches/Properly-handle-async-calls-to-restart-the-server.patch +++ b/Spigot-Server-Patches/Properly-handle-async-calls-to-restart-the-server.patch @@ -3,9 +3,35 @@ From: Zach Brown <1254957+zachbr@users.noreply.github.com> Date: Fri, 12 May 2017 23:34:11 -0500 Subject: [PATCH] Properly handle async calls to restart the server +The watchdog thread calls the server restart function asynchronously. Prior to +this change, it attempted to do several non-safe operations from the watchdog +thread, rather than the main. Specifically, because of a separate upstream change, +it causes player entities to be ticked asynchronously, among other things. +This is dangerous. + +This patch moves the old handling into a synchronous variant, for calls from the +restart command, and adds separate handling for async calls, such as those from +the watchdog thread. + +When calling from the watchdog thread, we cannot assume the main thread is in a +tickable state; it may be completely deadlocked. Therefore, we kill that thread +right then and there. + +diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java +index 8df30e3d0..df3077c9d 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 implements Runnable, ICommandListener, IAs + return this.ab; + } + ++ public final Thread getServerThread() { return this.aI(); } // Paper - OBFHELPER + public Thread aI() { + return this.serverThread; + } diff --git a/src/main/java/org/spigotmc/RestartCommand.java b/src/main/java/org/spigotmc/RestartCommand.java -index 49768734d..2361f96d0 100644 +index 49768734d..35c828805 100644 --- a/src/main/java/org/spigotmc/RestartCommand.java +++ b/src/main/java/org/spigotmc/RestartCommand.java @@ -0,0 +0,0 @@ public class RestartCommand extends Command @@ -81,7 +107,7 @@ index 49768734d..2361f96d0 100644 + } else + { + closeSocket(); -+ MinecraftServer.getServer().safeShutdown(); ++ MinecraftServer.getServer().getServerThread().stop(); + } + } +