reformat spigot package

This commit is contained in:
Lulu13022002
2024-12-16 19:22:36 +01:00
parent 7d29c678f7
commit 57c683647f
11 changed files with 559 additions and 1376 deletions
@@ -5,11 +5,12 @@ 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 class WatchdogThread extends Thread {
private static WatchdogThread instance;
private long timeoutTime;
@@ -21,160 +22,141 @@ public class WatchdogThread extends Thread
private volatile long lastTick;
private volatile boolean stopping;
private WatchdogThread(long timeoutTime, boolean restart)
{
super( "Paper Watchdog Thread" );
private WatchdogThread(long timeoutTime, boolean restart) {
super("Paper Watchdog Thread");
this.timeoutTime = timeoutTime;
this.restart = restart;
earlyWarningEvery = Math.min(io.papermc.paper.configuration.GlobalConfiguration.get().watchdog.earlyWarningEvery, timeoutTime); // Paper
earlyWarningDelay = Math.min(io.papermc.paper.configuration.GlobalConfiguration.get().watchdog.earlyWarningDelay, timeoutTime); // Paper
this.earlyWarningEvery = Math.min(GlobalConfiguration.get().watchdog.earlyWarningEvery, timeoutTime); // Paper
this.earlyWarningDelay = Math.min(GlobalConfiguration.get().watchdog.earlyWarningDelay, timeoutTime); // Paper
}
private static long monotonicMillis()
{
private static long monotonicMillis() {
return System.nanoTime() / 1000000L;
}
public static void doStart(int timeoutTime, boolean restart)
{
if ( WatchdogThread.instance == null )
{
WatchdogThread.instance = new WatchdogThread( timeoutTime * 1000L, restart );
public static void doStart(int timeoutTime, boolean restart) {
if (WatchdogThread.instance == null) {
WatchdogThread.instance = new WatchdogThread(timeoutTime * 1000L, restart);
WatchdogThread.instance.start();
} else
{
} else {
WatchdogThread.instance.timeoutTime = timeoutTime * 1000L;
WatchdogThread.instance.restart = restart;
}
}
public static void tick()
{
public static void tick() {
WatchdogThread.instance.lastTick = WatchdogThread.monotonicMillis();
}
public static void doStop()
{
if ( WatchdogThread.instance != null )
{
public static void doStop() {
if (WatchdogThread.instance != null) {
WatchdogThread.instance.stopping = true;
}
}
@Override
public void run()
{
while ( !this.stopping )
{
//
public void run() {
while (!this.stopping) {
// Paper start
Logger log = Bukkit.getServer().getLogger();
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 > lastTick + timeoutTime;
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;
// Don't spam early warning dumps
if ( !isLongTimeout && (earlyWarningEvery <= 0 || !hasStarted || currentTime < lastEarlyWarning + earlyWarningEvery || currentTime < lastTick + earlyWarningDelay)) continue;
if ( !isLongTimeout && MinecraftServer.getServer().hasStopped()) continue; // Don't spam early watchdog warnings during shutdown, we'll come back to this...
lastEarlyWarning = currentTime;
if (!isLongTimeout && (this.earlyWarningEvery <= 0 ||
!hasStarted || currentTime < this.lastEarlyWarning + this.earlyWarningEvery ||
currentTime < this.lastTick + this.earlyWarningDelay))
continue;
if (!isLongTimeout && MinecraftServer.getServer().hasStopped())
continue; // Don't spam early watchdog warnings during shutdown, we'll come back to this...
this.lastEarlyWarning = currentTime;
if (isLongTimeout) {
// Paper end
log.log( Level.SEVERE, "------------------------------" );
log.log( Level.SEVERE, "The server has stopped responding! This is (probably) not a Paper bug." ); // Paper
log.log( Level.SEVERE, "If you see a plugin in the Server thread dump below, then please report it to that author" );
log.log( Level.SEVERE, "\t *Especially* if it looks like HTTP or MySQL operations are occurring" );
log.log( Level.SEVERE, "If you see a world save or edit, then it means you did far more than your server can handle at once" );
log.log( Level.SEVERE, "\t If this is the case, consider increasing timeout-time in spigot.yml but note that this will replace the crash with LARGE lag spikes" );
log.log( Level.SEVERE, "If you are unsure or still think this is a Paper bug, please report this to https://github.com/PaperMC/Paper/issues" );
log.log( Level.SEVERE, "Be sure to include ALL relevant console errors and Minecraft crash reports" );
log.log( Level.SEVERE, "Paper version: " + Bukkit.getServer().getVersion() );
//
if ( net.minecraft.world.level.Level.lastPhysicsProblem != null )
{
log.log( Level.SEVERE, "------------------------------" );
log.log( Level.SEVERE, "During the run of the server, a physics stackoverflow was supressed" );
log.log( Level.SEVERE, "near " + net.minecraft.world.level.Level.lastPhysicsProblem );
}
//
// Paper start - Warn in watchdog if an excessive velocity was ever set
if (org.bukkit.craftbukkit.CraftServer.excessiveVelEx != null) {
log.log(Level.SEVERE, "------------------------------");
log.log(Level.SEVERE, "During the run of the server, a plugin set an excessive velocity on an entity");
log.log(Level.SEVERE, "This may be the cause of the issue, or it may be entirely unrelated");
log.log(Level.SEVERE, org.bukkit.craftbukkit.CraftServer.excessiveVelEx.getMessage());
for (StackTraceElement stack : org.bukkit.craftbukkit.CraftServer.excessiveVelEx.getStackTrace()) {
log.log( Level.SEVERE, "\t\t" + stack );
// Paper end
logger.log(Level.SEVERE, "------------------------------");
logger.log(Level.SEVERE, "The server has stopped responding! This is (probably) not a Paper bug."); // Paper
logger.log(Level.SEVERE, "If you see a plugin in the Server thread dump below, then please report it to that author");
logger.log(Level.SEVERE, "\t *Especially* if it looks like HTTP or MySQL operations are occurring");
logger.log(Level.SEVERE, "If you see a world save or edit, then it means you did far more than your server can handle at once");
logger.log(Level.SEVERE, "\t If this is the case, consider increasing timeout-time in spigot.yml but note that this will replace the crash with LARGE lag spikes");
logger.log(Level.SEVERE, "If you are unsure or still think this is a Paper bug, please report this to https://github.com/PaperMC/Paper/issues");
logger.log(Level.SEVERE, "Be sure to include ALL relevant console errors and Minecraft crash reports");
logger.log(Level.SEVERE, "Paper version: " + Bukkit.getServer().getVersion());
if (net.minecraft.world.level.Level.lastPhysicsProblem != null) {
logger.log(Level.SEVERE, "------------------------------");
logger.log(Level.SEVERE, "During the run of the server, a physics stackoverflow was supressed");
logger.log(Level.SEVERE, "near " + net.minecraft.world.level.Level.lastPhysicsProblem);
}
}
// Paper end
} else
{
log.log(Level.SEVERE, "--- DO NOT REPORT THIS TO PAPER - THIS IS NOT A BUG OR A CRASH - " + Bukkit.getServer().getVersion() + " ---");
log.log(Level.SEVERE, "The server has not responded for " + (currentTime - lastTick) / 1000 + " seconds! Creating thread dump");
// Paper start - Warn in watchdog if an excessive velocity was ever set
if (CraftServer.excessiveVelEx != null) {
logger.log(Level.SEVERE, "------------------------------");
logger.log(Level.SEVERE, "During the run of the server, a plugin set an excessive velocity on an entity");
logger.log(Level.SEVERE, "This may be the cause of the issue, or it may be entirely unrelated");
logger.log(Level.SEVERE, CraftServer.excessiveVelEx.getMessage());
for (StackTraceElement stack : CraftServer.excessiveVelEx.getStackTrace()) {
logger.log(Level.SEVERE, "\t\t" + stack);
}
}
// Paper end
} else {
logger.log(Level.SEVERE, "--- DO NOT REPORT THIS TO PAPER - THIS IS NOT A BUG OR A CRASH - " + Bukkit.getServer().getVersion() + " ---");
logger.log(Level.SEVERE, "The server has not responded for " + (currentTime - lastTick) / 1000 + " seconds! Creating thread dump");
}
// Paper end - Different message for short timeout
log.log( Level.SEVERE, "------------------------------" );
log.log( Level.SEVERE, "Server thread dump (Look for plugins here before reporting to Paper!):" ); // Paper
WatchdogThread.dumpThread( ManagementFactory.getThreadMXBean().getThreadInfo( MinecraftServer.getServer().serverThread.getId(), Integer.MAX_VALUE ), log );
log.log( Level.SEVERE, "------------------------------" );
//
logger.log(Level.SEVERE, "------------------------------");
logger.log(Level.SEVERE, "Server thread dump (Look for plugins here before reporting to Paper!):"); // Paper
WatchdogThread.dumpThread(ManagementFactory.getThreadMXBean().getThreadInfo(MinecraftServer.getServer().serverThread.getId(), Integer.MAX_VALUE), logger);
logger.log(Level.SEVERE, "------------------------------");
// Paper start - Only print full dump on long timeouts
if ( isLongTimeout )
{
log.log( Level.SEVERE, "Entire Thread Dump:" );
ThreadInfo[] threads = ManagementFactory.getThreadMXBean().dumpAllThreads( true, true );
for ( ThreadInfo thread : threads )
{
WatchdogThread.dumpThread( thread, log );
}
if (isLongTimeout) {
logger.log(Level.SEVERE, "Entire Thread Dump:");
ThreadInfo[] threads = ManagementFactory.getThreadMXBean().dumpAllThreads(true, true);
for (ThreadInfo thread : threads) {
WatchdogThread.dumpThread(thread, logger);
}
} else {
log.log(Level.SEVERE, "--- DO NOT REPORT THIS TO PAPER - THIS IS NOT A BUG OR A CRASH ---");
logger.log(Level.SEVERE, "--- DO NOT REPORT THIS TO PAPER - THIS IS NOT A BUG OR A CRASH ---");
}
log.log( Level.SEVERE, "------------------------------" );
logger.log(Level.SEVERE, "------------------------------");
if ( isLongTimeout )
{
if ( this.restart && !MinecraftServer.getServer().hasStopped() )
{
RestartCommand.restart();
if (isLongTimeout) {
if (this.restart && !MinecraftServer.getServer().hasStopped()) {
RestartCommand.restart();
}
break;
}
break;
} // Paper end
// Paper end
}
try
{
sleep( 1000 ); // Paper - Reduce check time to every second instead of every ten seconds, more consistent and allows for short timeout
} catch ( InterruptedException ex )
{
try {
sleep(1000); // Paper - Reduce check time to every second instead of every ten seconds, more consistent and allows for short timeout
} catch (InterruptedException ex) {
this.interrupt();
}
}
}
private static void dumpThread(ThreadInfo thread, Logger log)
{
log.log( Level.SEVERE, "------------------------------" );
//
log.log( Level.SEVERE, "Current Thread: " + thread.getThreadName() );
log.log( Level.SEVERE, "\tPID: " + thread.getThreadId()
+ " | Suspended: " + thread.isSuspended()
+ " | Native: " + thread.isInNative()
+ " | State: " + thread.getThreadState() );
if ( thread.getLockedMonitors().length != 0 )
{
log.log( Level.SEVERE, "\tThread is waiting on monitor(s):" );
for ( MonitorInfo monitor : thread.getLockedMonitors() )
{
log.log( Level.SEVERE, "\t\tLocked on:" + monitor.getLockedStackFrame() );
private static void dumpThread(ThreadInfo thread, Logger log) {
log.log(Level.SEVERE, "------------------------------");
log.log(Level.SEVERE, "Current Thread: " + thread.getThreadName());
log.log(Level.SEVERE, "\tPID: " + thread.getThreadId()
+ " | Suspended: " + thread.isSuspended()
+ " | Native: " + thread.isInNative()
+ " | State: " + thread.getThreadState());
if (thread.getLockedMonitors().length != 0) {
log.log(Level.SEVERE, "\tThread is waiting on monitor(s):");
for (MonitorInfo monitor : thread.getLockedMonitors()) {
log.log(Level.SEVERE, "\t\tLocked on:" + monitor.getLockedStackFrame());
}
}
log.log( Level.SEVERE, "\tStack:" );
//
for ( StackTraceElement stack : io.papermc.paper.util.StacktraceDeobfuscator.INSTANCE.deobfuscateStacktrace(thread.getStackTrace()) ) // Paper
{
log.log( Level.SEVERE, "\t\t" + stack );
log.log(Level.SEVERE, "\tStack:");
for (StackTraceElement stack : io.papermc.paper.util.StacktraceDeobfuscator.INSTANCE.deobfuscateStacktrace(thread.getStackTrace())) { // Paper
log.log(Level.SEVERE, "\t\t" + stack);
}
}
}