2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Shane Freeder <theboyetronic@gmail.com>
Date: Thu, 18 Feb 2021 20:23:28 +0000
Subject: [PATCH] misc debugging dumps
diff --git a/src/main/java/io/papermc/paper/util/TraceUtil.java b/src/main/java/io/papermc/paper/util/TraceUtil.java
new file mode 100644
2024-04-25 06:38:28 +02:00
index 0000000000000000000000000000000000000000..479bb92d159f33c54c2d9c39d8a63aa9e74d95b9
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/io/papermc/paper/util/TraceUtil.java
2024-04-25 06:38:28 +02:00
@@ -0,0 +1,25 @@
2021-06-11 14:02:28 +02:00
+package io.papermc.paper.util;
+
+import org.bukkit.Bukkit;
+
+public final class TraceUtil {
+
+ public static void dumpTraceForThread(Thread thread, String reason) {
+ Bukkit.getLogger().warning(thread.getName() + ": " + reason);
2024-04-25 06:38:28 +02:00
+ StackTraceElement[] trace = StacktraceDeobfuscator.INSTANCE.deobfuscateStacktrace(thread.getStackTrace());
2021-06-11 14:02:28 +02:00
+ for (StackTraceElement traceElement : trace) {
+ Bukkit.getLogger().warning("\tat " + traceElement);
+ }
+ }
+
+ public static void dumpTraceForThread(String reason) {
2024-04-25 06:38:28 +02:00
+ final Throwable thr = new Throwable(reason);
+ StacktraceDeobfuscator.INSTANCE.deobfuscateThrowable(thr);
+ thr.printStackTrace();
+ }
+
+ public static void printStackTrace(Throwable thr) {
+ StacktraceDeobfuscator.INSTANCE.deobfuscateThrowable(thr);
+ thr.printStackTrace();
2021-06-11 14:02:28 +02:00
+ }
+}
2024-01-11 17:15:17 +01:00
diff --git a/src/main/java/net/minecraft/commands/Commands.java b/src/main/java/net/minecraft/commands/Commands.java
2024-10-23 16:04:01 +02:00
index c847fbdb6f52386570eb4c070fcc01d39cc52151..a7eb2a37a81a414dcb19319c075faefe0382aeba 100644
2024-01-11 17:15:17 +01:00
--- a/src/main/java/net/minecraft/commands/Commands.java
+++ b/src/main/java/net/minecraft/commands/Commands.java
2024-10-23 16:04:01 +02:00
@@ -345,7 +345,7 @@ public class Commands {
2024-01-11 17:15:17 +01:00
} catch (Exception exception) {
MutableComponent ichatmutablecomponent = Component.literal(exception.getMessage() == null ? exception.getClass().getName() : exception.getMessage());
- if (Commands.LOGGER.isDebugEnabled()) {
2024-01-21 12:11:43 +01:00
+ if (commandlistenerwrapper.getServer().isDebugging() || Commands.LOGGER.isDebugEnabled()) { // Paper - Debugging
2024-01-11 17:15:17 +01:00
Commands.LOGGER.error("Command exception: /{}", s, exception);
StackTraceElement[] astacktraceelement = exception.getStackTrace();
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
2024-10-26 03:13:48 +02:00
index 5cc5f4c0a91e7c667e9271de17ffa845f566bd4d..07045495e7d3f7e256bf30a777a5a7536dfe2446 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-10-23 16:04:01 +02:00
@@ -931,6 +931,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2024-01-23 12:06:27 +01:00
2021-06-11 14:02:28 +02:00
// CraftBukkit start
private boolean hasStopped = false;
2024-01-21 12:11:43 +01:00
+ private boolean hasLoggedStop = false; // Paper - Debugging
2021-06-11 14:02:28 +02:00
private final Object stopLock = new Object();
public final boolean hasStopped() {
2021-06-15 04:59:31 +02:00
synchronized (this.stopLock) {
2024-10-23 16:04:01 +02:00
@@ -945,6 +946,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2021-06-15 04:59:31 +02:00
if (this.hasStopped) return;
this.hasStopped = true;
2021-06-11 14:02:28 +02:00
}
2024-01-21 12:11:43 +01:00
+ if (!hasLoggedStop && isDebugging()) io.papermc.paper.util.TraceUtil.dumpTraceForThread("Server stopped"); // Paper - Debugging
2024-01-23 12:06:27 +01:00
// CraftBukkit end
if (this.metricsRecorder.isRecording()) {
this.cancelRecordingMetrics();
2024-10-23 16:04:01 +02:00
@@ -1049,6 +1051,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2021-06-15 04:59:31 +02:00
}
2022-12-07 21:16:54 +01:00
public void safeShutdown(boolean waitForShutdown, boolean isRestarting) {
2021-06-11 14:02:28 +02:00
this.isRestarting = isRestarting;
2024-01-21 12:11:43 +01:00
+ this.hasLoggedStop = true; // Paper - Debugging
+ if (isDebugging()) io.papermc.paper.util.TraceUtil.dumpTraceForThread("Server stopped"); // Paper - Debugging
2021-06-15 04:59:31 +02:00
// Paper end
this.running = false;
2022-12-07 21:16:54 +01:00
if (waitForShutdown) {
2023-09-22 06:05:18 +02:00
diff --git a/src/main/java/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java
2024-06-14 14:11:52 +02:00
index 5457358bc76889153036818fdfd70a043ec4e40f..880e5c52746e9e3a9a1f42ec6461be54e3ee136c 100644
2023-09-22 06:05:18 +02:00
--- a/src/main/java/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java
2024-06-13 22:14:13 +02:00
@@ -70,6 +70,10 @@ public class ServerConfigurationPacketListenerImpl extends ServerCommonPacketLis
2024-02-23 14:54:52 +01:00
@Override
2024-06-13 22:14:13 +02:00
public void onDisconnect(DisconnectionDetails info) {
2024-02-23 14:54:52 +01:00
+ // Paper start - Debugging
+ if (net.minecraft.server.MinecraftServer.getServer().isDebugging()) {
2024-06-14 14:11:52 +02:00
+ ServerConfigurationPacketListenerImpl.LOGGER.info("{} lost connection: {}, while in configuration phase {}", this.gameProfile, info.reason().getString(), currentTask != null ? currentTask.type().id() : "null");
2024-02-23 14:54:52 +01:00
+ } else // Paper end
2024-06-13 22:14:13 +02:00
ServerConfigurationPacketListenerImpl.LOGGER.info("{} lost connection: {}", this.gameProfile, info.reason().getString());
super.onDisconnect(info);
2024-02-23 14:54:52 +01:00
}
2024-06-13 22:14:13 +02:00
@@ -169,6 +173,11 @@ public class ServerConfigurationPacketListenerImpl extends ServerCommonPacketLis
2024-04-24 08:44:48 +02:00
playerlist.placeNewPlayer(this.connection, entityplayer, this.createCookie(this.clientInformation));
2023-09-22 06:05:18 +02:00
} catch (Exception exception) {
ServerConfigurationPacketListenerImpl.LOGGER.error("Couldn't place player in world", exception);
2024-01-21 12:11:43 +01:00
+ // Paper start - Debugging
2023-09-22 06:05:18 +02:00
+ if (MinecraftServer.getServer().isDebugging()) {
+ exception.printStackTrace();
+ }
2024-01-21 12:11:43 +01:00
+ // Paper end - Debugging
2023-09-22 06:05:18 +02:00
this.connection.send(new ClientboundDisconnectPacket(ServerConfigurationPacketListenerImpl.DISCONNECT_REASON_INVALID_DATA));
this.connection.disconnect(ServerConfigurationPacketListenerImpl.DISCONNECT_REASON_INVALID_DATA);
}
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-10-23 16:04:01 +02:00
index f5b0aa5ee92b24fd53d83eb45df1a5dece10733f..0d36eb7ae9d07d51449a4a15a6474c3f4befec94 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-10-23 16:04:01 +02:00
@@ -1052,6 +1052,7 @@ public final class CraftServer implements Server {
2021-09-11 19:27:48 +02:00
plugin.getDescription().getFullName(),
2021-06-11 14:02:28 +02:00
"This plugin is not properly shutting down its async tasks when it is being reloaded. This may cause conflicts with the newly loaded version of the plugin"
));
2024-01-21 12:11:43 +01:00
+ if (console.isDebugging()) io.papermc.paper.util.TraceUtil.dumpTraceForThread(worker.getThread(), "still running"); // Paper - Debugging
2021-06-11 14:02:28 +02:00
}
2023-02-23 18:58:50 +01:00
io.papermc.paper.plugin.PluginInitializerManager.reload(this.console); // Paper
2021-06-15 04:59:31 +02:00
this.loadPlugins();