Publicly execute the main thread at dawn

GH-684

Better handles most true deadlock situations
This commit is contained in:
Zach Brown 2017-05-13 05:51:09 -05:00
parent 302f743310
commit 54e5a2e4da
2 changed files with 30 additions and 4 deletions

View file

@ -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;

View file

@ -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();
+ }
+ }
+