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-06-17 21:21:06 +02:00
index e25fc35716aff1d1805884b18f67b0eb33d8c05c..8ca9ac8eff9d605baa878ca24e165ac5642bf160 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-06-13 22:14:13 +02:00
@@ -340,7 +340,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-07-17 19:24:53 +02:00
index ff73167bfe210305491e35f18adc2755d3651a85..1088a91ee131d1c303961557d8fb90101c2d8d3b 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-06-13 22:14:13 +02:00
@@ -916,6 +916,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-06-13 22:14:13 +02:00
@@ -930,6 +931,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-06-13 22:14:13 +02:00
@@ -1034,6 +1036,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-07-18 10:13:20 +02:00
index 6707e213d9bd2b173928b1e9dae87c403342953b..b36d62380a939a0b777fecf1472645f148289a6c 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-07-18 10:13:20 +02:00
@@ -1047,6 +1047,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();