2021-06-11 14:02:28 +02:00
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
2024-04-27 01:17:13 +02:00
index c0d467cc65c208aa1166a24dec753b1e2b3d995b..6da91e7236ee2d2a0bcbe1f3933b562425ec06a5 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
2024-04-24 08:44:48 +02:00
@@ -939,6 +939,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2021-06-11 14:02:28 +02:00
// CraftBukkit start
if (this.server != null) {
this.server.disablePlugins();
2024-01-21 12:11:43 +01:00
+ this.server.waitForAsyncTasksShutdown(); // Paper - Wait for Async Tasks during shutdown
2021-06-11 14:02:28 +02:00
}
// CraftBukkit end
2024-04-24 08:44:48 +02:00
if (io.papermc.paper.plugin.PluginInitializerManager.instance().pluginRemapper != null) io.papermc.paper.plugin.PluginInitializerManager.instance().pluginRemapper.shutdown(); // Paper - Plugin remapping
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
2024-04-24 08:44:48 +02:00
index 3f29c1ba155ab3b145d241efb3f9274ef7a279e2..11c41e2a0887a59b7b3328b28628ce5958fc06d2 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
2024-04-24 08:44:48 +02:00
@@ -1029,6 +1029,31 @@ public final class CraftServer implements Server {
2021-06-11 14:02:28 +02:00
org.spigotmc.WatchdogThread.hasStarted = true; // Paper - Disable watchdog early timeout on reload
}
2024-01-21 12:11:43 +01:00
+ // Paper start - Wait for Async Tasks during shutdown
2021-06-11 14:02:28 +02:00
+ 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(
2023-04-16 18:49:13 +02:00
+ "Nag author(s): '%s' of '%s' about the following: %s",
+ plugin.getPluginMeta().getAuthors(),
+ plugin.getPluginMeta().getDisplayName(),
2021-06-11 14:02:28 +02:00
+ "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."
+ ));
+ }
+ }
2024-01-21 12:11:43 +01:00
+ // Paper end - Wait for Async Tasks during shutdown
2021-06-11 14:02:28 +02:00
+
@Override
public void reloadData() {
2023-10-27 01:34:58 +02:00
ReloadCommand.reload(this.console);