diff options
Diffstat (limited to 'patches/server/0358-Wait-for-Async-Tasks-during-shutdown.patch')
-rw-r--r-- | patches/server/0358-Wait-for-Async-Tasks-during-shutdown.patch | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/patches/server/0358-Wait-for-Async-Tasks-during-shutdown.patch b/patches/server/0358-Wait-for-Async-Tasks-during-shutdown.patch new file mode 100644 index 0000000000..289e0129e9 --- /dev/null +++ b/patches/server/0358-Wait-for-Async-Tasks-during-shutdown.patch @@ -0,0 +1,60 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Aikar <[email protected]> +Date: Sun, 10 May 2020 22:16:17 -0400 +Subject: [PATCH] Wait for Async Tasks during shutdown + +Server.reload() had this logic to give time for tasks to shutdown, +however shutdown did not... + +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 8b17df3d18fe9acc1a7b10c6809886da0143f8c5..0370d26bd1e1d2fe1d640b052aca8a9c05dcb9dc 100644 +--- a/src/main/java/net/minecraft/server/MinecraftServer.java ++++ b/src/main/java/net/minecraft/server/MinecraftServer.java +@@ -942,6 +942,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa + // CraftBukkit start + if (this.server != null) { + this.server.disablePlugins(); ++ this.server.waitForAsyncTasksShutdown(); // Paper - Wait for Async Tasks during shutdown + } + // CraftBukkit end + if (io.papermc.paper.plugin.PluginInitializerManager.instance().pluginRemapper != null) io.papermc.paper.plugin.PluginInitializerManager.instance().pluginRemapper.shutdown(); // Paper - Plugin remapping +diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java +index 48c3d926682dd72ba476b4afc9e44e0113af0b46..610661dec58b9170d2eb2093c7fab81585ff9a2c 100644 +--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java ++++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java +@@ -1058,6 +1058,32 @@ public final class CraftServer implements Server { + org.spigotmc.WatchdogThread.hasStarted = true; // Paper - Disable watchdog early timeout on reload + } + ++ // Paper start - Wait for Async Tasks during shutdown ++ public void waitForAsyncTasksShutdown() { ++ int pollCount = 0; ++ ++ // Wait for at most 5 seconds for plugins to close their threads ++ while (pollCount < 10*5 && getScheduler().getActiveWorkers().size() > 0) { ++ try { ++ Thread.sleep(100); ++ } catch (InterruptedException e) {} ++ pollCount++; ++ } ++ ++ List<BukkitWorker> overdueWorkers = getScheduler().getActiveWorkers(); ++ for (BukkitWorker worker : overdueWorkers) { ++ Plugin plugin = worker.getOwner(); ++ getLogger().log(Level.SEVERE, String.format( ++ "Nag author(s): '%s' of '%s' about the following: %s", ++ plugin.getPluginMeta().getAuthors(), ++ plugin.getPluginMeta().getDisplayName(), ++ "This plugin is not properly shutting down its async tasks when it is being shut down. This task may throw errors during the final shutdown logs and might not complete before process dies." ++ )); ++ if (console.isDebugging()) io.papermc.paper.util.TraceUtil.dumpTraceForThread(worker.getThread(), "still running"); // Paper - Debugging ++ } ++ } ++ // Paper end - Wait for Async Tasks during shutdown ++ + @Override + public void reloadData() { + ReloadCommand.reload(this.console); |