aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorZach Brown <[email protected]>2017-05-12 23:49:59 -0500
committerZach Brown <[email protected]>2017-05-12 23:49:59 -0500
commitb0d78d461b4037459d393528faa699d0b4fe9b46 (patch)
tree2f5380da4d7ae7359c47da56a4f961b2eab8bac0
parent6c3faf6aa31eec31563d495f2af638e6d7d7bb5f (diff)
downloadPaper-b0d78d461b4037459d393528faa699d0b4fe9b46.tar.gz
Paper-b0d78d461b4037459d393528faa699d0b4fe9b46.zip
Properly handle async calls to restart the server
GH-681
-rw-r--r--Spigot-Server-Patches/0211-Properly-handle-async-calls-to-restart-the-server.patch105
1 files changed, 105 insertions, 0 deletions
diff --git a/Spigot-Server-Patches/0211-Properly-handle-async-calls-to-restart-the-server.patch b/Spigot-Server-Patches/0211-Properly-handle-async-calls-to-restart-the-server.patch
new file mode 100644
index 0000000000..1797044dcd
--- /dev/null
+++ b/Spigot-Server-Patches/0211-Properly-handle-async-calls-to-restart-the-server.patch
@@ -0,0 +1,105 @@
+From 707945410e0af095ceb20fde3ce0eaf085c36c8c Mon Sep 17 00:00:00 2001
+From: Zach Brown <[email protected]>
+Date: Fri, 12 May 2017 23:34:11 -0500
+Subject: [PATCH] Properly handle async calls to restart the server
+
+
+diff --git a/src/main/java/org/spigotmc/RestartCommand.java b/src/main/java/org/spigotmc/RestartCommand.java
+index 49768734d..2361f96d0 100644
+--- a/src/main/java/org/spigotmc/RestartCommand.java
++++ b/src/main/java/org/spigotmc/RestartCommand.java
+@@ -52,36 +52,7 @@ public class RestartCommand extends Command
+ // Disable Watchdog
+ WatchdogThread.doStop();
+
+- // Kick all players
+- for ( EntityPlayer p : (List< EntityPlayer>) MinecraftServer.getServer().getPlayerList().players )
+- {
+- p.playerConnection.disconnect(SpigotConfig.restartMessage);
+- }
+- // Give the socket a chance to send the packets
+- try
+- {
+- Thread.sleep( 100 );
+- } catch ( InterruptedException ex )
+- {
+- }
+- // Close the socket so we can rebind with the new process
+- MinecraftServer.getServer().getServerConnection().b();
+-
+- // Give time for it to kick in
+- try
+- {
+- Thread.sleep( 100 );
+- } catch ( InterruptedException ex )
+- {
+- }
+-
+- // Actually shutdown
+- try
+- {
+- MinecraftServer.getServer().stop();
+- } catch ( Throwable t )
+- {
+- }
++ shutdownServer(); // Paper - Moved to function that will handle sync and async
+
+ // This will be done AFTER the server has completely halted
+ Thread shutdownHook = new Thread()
+@@ -129,4 +100,53 @@ public class RestartCommand extends Command
+ ex.printStackTrace();
+ }
+ }
++
++ // Paper start - sync copied from above with minor changes, async added
++ private static void shutdownServer()
++ {
++ if (MinecraftServer.getServer().isMainThread())
++ {
++ // Kick all players
++ for ( EntityPlayer p : com.google.common.collect.ImmutableList.copyOf( MinecraftServer.getServer().getPlayerList().players ) )
++ {
++ p.playerConnection.disconnect(SpigotConfig.restartMessage);
++ }
++ // Give the socket a chance to send the packets
++ try
++ {
++ Thread.sleep( 100 );
++ } catch ( InterruptedException ex )
++ {
++ }
++
++ closeSocket();
++
++ // Actually shutdown
++ try
++ {
++ MinecraftServer.getServer().stop();
++ } catch ( Throwable t )
++ {
++ }
++ } else
++ {
++ closeSocket();
++ MinecraftServer.getServer().safeShutdown();
++ }
++ }
++
++ // Paper - Split from moved code
++ private static void closeSocket() {
++ // Close the socket so we can rebind with the new process
++ MinecraftServer.getServer().getServerConnection().b();
++
++ // Give time for it to kick in
++ try
++ {
++ Thread.sleep( 100 );
++ } catch ( InterruptedException ex )
++ {
++ }
++ }
++ // Paper end
+ }
+--
+2.13.0.windows.1
+