Update watchdog patches
This commit is contained in:
@@ -12,11 +12,27 @@ public class ServerShutdownThread extends Thread {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
// Paper start - try to shutdown on main
|
||||
server.safeShutdown(false, false);
|
||||
for (int i = 1000; i > 0 && !server.hasStopped(); i -= 100) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
if (server.hasStopped()) {
|
||||
while (!server.hasFullyShutdown) Thread.sleep(1000);
|
||||
return;
|
||||
}
|
||||
// Looks stalled, close async
|
||||
org.spigotmc.AsyncCatcher.enabled = false; // Spigot
|
||||
server.forceTicks = true;
|
||||
this.server.close();
|
||||
while (!server.hasFullyShutdown) Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
// Paper end
|
||||
} finally {
|
||||
org.apache.logging.log4j.LogManager.shutdown(); // Paper
|
||||
try {
|
||||
net.minecrell.terminalconsole.TerminalConsoleAppender.close(); // Paper - Use TerminalConsoleAppender
|
||||
//net.minecrell.terminalconsole.TerminalConsoleAppender.close(); // Paper - Move into stop
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ public class RestartCommand extends Command {
|
||||
// Paper end
|
||||
|
||||
// Paper start - copied from above and modified to return if the hook registered
|
||||
private static boolean addShutdownHook(String restartScript) {
|
||||
public static boolean addShutdownHook(String restartScript) {
|
||||
String[] split = restartScript.split(" ");
|
||||
if (split.length > 0 && new File(split[0]).isFile()) {
|
||||
Thread shutdownHook = new Thread(() -> {
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
package org.spigotmc;
|
||||
|
||||
import io.papermc.paper.FeatureHooks;
|
||||
import io.papermc.paper.configuration.GlobalConfiguration;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.MonitorInfo;
|
||||
import java.lang.management.ThreadInfo;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import io.papermc.paper.configuration.GlobalConfiguration;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
|
||||
public class WatchdogThread extends Thread {
|
||||
|
||||
public static final boolean DISABLE_WATCHDOG = Boolean.getBoolean("disable.watchdog"); // Paper - Improved watchdog support
|
||||
private static WatchdogThread instance;
|
||||
private long timeoutTime;
|
||||
private boolean restart;
|
||||
@@ -36,6 +38,7 @@ public class WatchdogThread extends Thread {
|
||||
|
||||
public static void doStart(int timeoutTime, boolean restart) {
|
||||
if (WatchdogThread.instance == null) {
|
||||
if (timeoutTime <= 0) timeoutTime = 300; // Paper
|
||||
WatchdogThread.instance = new WatchdogThread(timeoutTime * 1000L, restart);
|
||||
WatchdogThread.instance.start();
|
||||
} else {
|
||||
@@ -60,14 +63,15 @@ public class WatchdogThread extends Thread {
|
||||
// Paper start
|
||||
Logger logger = Bukkit.getServer().getLogger();
|
||||
long currentTime = WatchdogThread.monotonicMillis();
|
||||
if (this.lastTick != 0 && this.timeoutTime > 0 && currentTime > this.lastTick + this.earlyWarningEvery && !Boolean.getBoolean("disable.watchdog")) { // Paper - Add property to disable
|
||||
boolean isLongTimeout = currentTime > this.lastTick + this.timeoutTime;
|
||||
MinecraftServer server = MinecraftServer.getServer();
|
||||
if (this.lastTick != 0 && this.timeoutTime > 0 && WatchdogThread.hasStarted && (!server.isRunning() || (currentTime > this.lastTick + this.earlyWarningEvery && !DISABLE_WATCHDOG))) { // Paper - add property to disable
|
||||
boolean isLongTimeout = currentTime > this.lastTick + this.timeoutTime || (!server.isRunning() && !server.hasStopped() && currentTime > this.lastTick + 1000);
|
||||
// Don't spam early warning dumps
|
||||
if (!isLongTimeout && (this.earlyWarningEvery <= 0 ||
|
||||
!hasStarted || currentTime < this.lastEarlyWarning + this.earlyWarningEvery ||
|
||||
currentTime < this.lastTick + this.earlyWarningDelay))
|
||||
continue;
|
||||
if (!isLongTimeout && MinecraftServer.getServer().hasStopped())
|
||||
if (!isLongTimeout && server.hasStopped())
|
||||
continue; // Don't spam early watchdog warnings during shutdown, we'll come back to this...
|
||||
this.lastEarlyWarning = currentTime;
|
||||
if (isLongTimeout) {
|
||||
@@ -106,6 +110,7 @@ public class WatchdogThread extends Thread {
|
||||
// Paper end - Different message for short timeout
|
||||
logger.log(Level.SEVERE, "------------------------------");
|
||||
logger.log(Level.SEVERE, "Server thread dump (Look for plugins here before reporting to Paper!):"); // Paper
|
||||
FeatureHooks.dumpTickingInfo(); // Paper - log detailed tick information
|
||||
WatchdogThread.dumpThread(ManagementFactory.getThreadMXBean().getThreadInfo(MinecraftServer.getServer().serverThread.getId(), Integer.MAX_VALUE), logger);
|
||||
logger.log(Level.SEVERE, "------------------------------");
|
||||
|
||||
@@ -123,8 +128,23 @@ public class WatchdogThread extends Thread {
|
||||
logger.log(Level.SEVERE, "------------------------------");
|
||||
|
||||
if (isLongTimeout) {
|
||||
if (this.restart && !MinecraftServer.getServer().hasStopped()) {
|
||||
RestartCommand.restart();
|
||||
if (!server.hasStopped()) {
|
||||
AsyncCatcher.enabled = false; // Disable async catcher incase it interferes with us
|
||||
server.forceTicks = true;
|
||||
if (this.restart) {
|
||||
RestartCommand.addShutdownHook(SpigotConfig.restartScript);
|
||||
}
|
||||
// try one last chance to safe shutdown on main incase it 'comes back'
|
||||
server.abnormalExit = true;
|
||||
server.safeShutdown(false, this.restart);
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (!server.hasStopped()) {
|
||||
server.close();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user