aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0389-misc-debugging-dumps.patch
blob: e2ab0e9a0654712ef3b1a9e741c3f4e944975e9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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
index 0000000000000000000000000000000000000000..2d5494d2813b773e60ddba6790b750a9a08f21f8
--- /dev/null
+++ b/src/main/java/io/papermc/paper/util/TraceUtil.java
@@ -0,0 +1,18 @@
+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);
+        StackTraceElement[] trace = thread.getStackTrace();
+        for (StackTraceElement traceElement : trace) {
+            Bukkit.getLogger().warning("\tat " + traceElement);
+        }
+    }
+
+    public static void dumpTraceForThread(String reason) {
+        new Throwable(reason).printStackTrace();
+    }
+}
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 5f8cf962a4b630223fb93ffea49d1b2151e1604d..fdaf757cbbc90841747989add56c13f252f645e5 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -872,6 +872,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
     // CraftBukkit start
     private boolean hasStopped = false;
     public volatile boolean hasFullyShutdown = false; // Paper
+    private boolean hasLoggedStop = false; // Paper
     private final Object stopLock = new Object();
     public final boolean hasStopped() {
         synchronized (this.stopLock) {
@@ -886,6 +887,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
             if (this.hasStopped) return;
             this.hasStopped = true;
         }
+        if (!hasLoggedStop && isDebugging()) io.papermc.paper.util.TraceUtil.dumpTraceForThread("Server stopped"); // Paper
         // Paper start - kill main thread, and kill it hard
         shutdownThread = Thread.currentThread();
         org.spigotmc.WatchdogThread.doStop(); // Paper
@@ -986,6 +988,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
     }
     public void safeShutdown(boolean waitForShutdown, boolean isRestarting) {
         this.isRestarting = isRestarting;
+        this.hasLoggedStop = true; // Paper
+        if (isDebugging()) io.papermc.paper.util.TraceUtil.dumpTraceForThread("Server stopped"); // Paper
         // Paper end
         this.running = false;
         if (waitForShutdown) {
diff --git a/src/main/java/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java
index ed80d9551cd7cc1ec26a5d5fd7bc185b38fddd78..77e19f345bf68d12686a65e669cd597cd92af910 100644
--- a/src/main/java/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java
@@ -131,6 +131,11 @@ public class ServerConfigurationPacketListenerImpl extends ServerCommonPacketLis
             this.connection.resumeInboundAfterProtocolChange();
         } catch (Exception exception) {
             ServerConfigurationPacketListenerImpl.LOGGER.error("Couldn't place player in world", exception);
+            // Paper start
+            if (MinecraftServer.getServer().isDebugging()) {
+                exception.printStackTrace();
+            }
+            // Paper end
             this.connection.send(new ClientboundDisconnectPacket(ServerConfigurationPacketListenerImpl.DISCONNECT_REASON_INVALID_DATA));
             this.connection.disconnect(ServerConfigurationPacketListenerImpl.DISCONNECT_REASON_INVALID_DATA);
         }
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 914f4673a0add2b14bcba389eed799e599984616..753dc48330acc93b8ddbd9ed8f5c9655c72ff311 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -1010,6 +1010,7 @@ public final class CraftServer implements Server {
                 plugin.getDescription().getFullName(),
                 "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"
             ));
+            if (console.isDebugging()) io.papermc.paper.util.TraceUtil.dumpTraceForThread(worker.getThread(), "still running"); // Paper
         }
         io.papermc.paper.plugin.PluginInitializerManager.reload(this.console); // Paper
         this.loadPlugins();