Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-11-15 12:30:06 +01:00
e224f0bdab
We had 2 issues. 1) Log4J2 Shutdown hook seemed to be causing issues as it shutdown logger while we still needed it 2) ServerShutdownThread needs to stay alive until server is shutdown to keep jvm open. It appears SIGINT is handled differently than SIGTERM, as SIGINT worked correctly. But this will make both methods work.
64 Zeilen
2.9 KiB
Diff
64 Zeilen
2.9 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 2c9ae5c46a39639fd9f842df23993a47b31c8585..4ab6579032043f570c20befa7fef8931babd2355 100644
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
@@ -747,6 +747,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
|
|
// CraftBukkit start
|
|
if (this.server != null) {
|
|
this.server.disablePlugins();
|
|
+ this.server.waitForAsyncTasksShutdown(); // Paper
|
|
}
|
|
// CraftBukkit end
|
|
if (this.getServerConnection() != null) {
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
index c2b7cb36052455eef2100a1924dc76a5921fa858..894917c8891a951edb251f019529d0f7bec7037d 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
@@ -895,6 +895,35 @@ 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();
|
|
+ String author = "<NoAuthorGiven>";
|
|
+ if (plugin.getDescription().getAuthors().size() > 0) {
|
|
+ author = plugin.getDescription().getAuthors().get(0);
|
|
+ }
|
|
+ getLogger().log(Level.SEVERE, String.format(
|
|
+ "Nag author: '%s' of '%s' about the following: %s",
|
|
+ author,
|
|
+ plugin.getDescription().getName(),
|
|
+ "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() {
|
|
console.reload();
|