Paper/patches/server/0393-Wait-for-Async-Tasks-during-shutdown.patch
Jake Potrebic 1e7dd72f15
Remove 'fix Vanilla Minecart speed' patch (#10068)
The game uses 0.95d now
2023-12-22 17:44:36 -08:00

60 lines
2.8 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
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 e230a6e3810929c2f9ac70a98c9fc41734ec06c2..81d4870060ea418fecfdd01f1357899038c95fe9 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -958,6 +958,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
// CraftBukkit start
if (this.server != null) {
this.server.disablePlugins();
+ this.server.waitForAsyncTasksShutdown(); // Paper
}
// CraftBukkit end
this.getConnection().stop();
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 7ffd0447becaaaf4f26fa5a6be7f6d83bd816fb3..dfe8d6d8b592a7dc9b1f1d7fb68d0960dbeb387f 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -1016,6 +1016,31 @@ public final class CraftServer implements Server {
org.spigotmc.WatchdogThread.hasStarted = true; // Paper - Disable watchdog early timeout on reload
}
+ // Paper start
+ 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."
+ ));
+ }
+ }
+ // Paper end
+
@Override
public void reloadData() {
ReloadCommand.reload(this.console);