Fix deadlock issue with watchdog stopping

Fixes #4008
This commit is contained in:
Aikar 2020-07-28 22:19:01 -04:00
parent baf1fabe9e
commit 0d19e4579b
No known key found for this signature in database
GPG key ID: 401ADFC9891FAAFE
4 changed files with 32 additions and 36 deletions

View file

@ -109,7 +109,7 @@ index 63fdae15ccbef0c39718b320dbd096794bcfa3b4..6beefff203ed6e448898eb5b2e95800d
} }
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 04eb2af28f9843ef7641f5464d2a043c696de864..d9ed9df3021dab1f5ee0a51215a002253ac1e34c 100644 index 04eb2af28f9843ef7641f5464d2a043c696de864..fb65978d783a91b341658e0ebe393ab77153a0d9 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java --- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -159,7 +159,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas @@ -159,7 +159,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
@ -138,15 +138,15 @@ index 04eb2af28f9843ef7641f5464d2a043c696de864..d9ed9df3021dab1f5ee0a51215a00225
private final Object stopLock = new Object(); private final Object stopLock = new Object();
public final boolean hasStopped() { public final boolean hasStopped() {
synchronized (stopLock) { synchronized (stopLock) {
@@ -749,10 +752,22 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas @@ -751,6 +754,19 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
// CraftBukkit start - prevent double stopping on multiple threads
synchronized(stopLock) {
if (hasStopped) return; if (hasStopped) return;
+ shutdownThread = Thread.currentThread();
hasStopped = true; hasStopped = true;
+ org.spigotmc.WatchdogThread.doStop(); // Paper }
+ // Paper start - kill main thread, and kill it hard + // Paper start - kill main thread, and kill it hard
+ shutdownThread = Thread.currentThread();
+ org.spigotmc.WatchdogThread.doStop(); // Paper
+ if (!isMainThread()) { + if (!isMainThread()) {
+ MinecraftServer.LOGGER.info("Stopping main thread (Ignore any thread death message you see! - DO NOT REPORT THREAD DEATH TO PAPER)");
+ while (this.getThread().isAlive()) { + while (this.getThread().isAlive()) {
+ this.getThread().stop(); + this.getThread().stop();
+ try { + try {
@ -155,14 +155,10 @@ index 04eb2af28f9843ef7641f5464d2a043c696de864..d9ed9df3021dab1f5ee0a51215a00225
+ } + }
+ } + }
+ // Paper end + // Paper end
}
// CraftBukkit end // CraftBukkit end
- MinecraftServer.LOGGER.info("Stopping server"); MinecraftServer.LOGGER.info("Stopping server");
+ MinecraftServer.LOGGER.info("Stopping server (Ignore any thread death message you see! - DO NOT REPORT THREAD DEATH TO PAPER)"); // Paper
MinecraftTimings.stopServer(); // Paper MinecraftTimings.stopServer(); // Paper
// CraftBukkit start @@ -816,7 +832,18 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
if (this.server != null) {
@@ -816,7 +831,18 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
this.getUserCache().c(false); // Paper this.getUserCache().c(false); // Paper
} }
// Spigot end // Spigot end
@ -181,7 +177,7 @@ index 04eb2af28f9843ef7641f5464d2a043c696de864..d9ed9df3021dab1f5ee0a51215a00225
} }
public String getServerIp() { public String getServerIp() {
@@ -909,6 +935,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas @@ -909,6 +936,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
protected void v() { protected void v() {
try { try {
@ -189,7 +185,7 @@ index 04eb2af28f9843ef7641f5464d2a043c696de864..d9ed9df3021dab1f5ee0a51215a00225
if (this.init()) { if (this.init()) {
this.nextTick = SystemUtils.getMonotonicMillis(); this.nextTick = SystemUtils.getMonotonicMillis();
this.serverPing.setMOTD(new ChatComponentText(this.motd)); this.serverPing.setMOTD(new ChatComponentText(this.motd));
@@ -916,6 +943,18 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas @@ -916,6 +944,18 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
this.a(this.serverPing); this.a(this.serverPing);
// Spigot start // Spigot start
@ -208,7 +204,7 @@ index 04eb2af28f9843ef7641f5464d2a043c696de864..d9ed9df3021dab1f5ee0a51215a00225
org.spigotmc.WatchdogThread.hasStarted = true; // Paper org.spigotmc.WatchdogThread.hasStarted = true; // Paper
Arrays.fill( recentTps, 20 ); Arrays.fill( recentTps, 20 );
long start = System.nanoTime(), curTime, tickSection = start; // Paper - Further improve server tick loop long start = System.nanoTime(), curTime, tickSection = start; // Paper - Further improve server tick loop
@@ -971,6 +1010,12 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas @@ -971,6 +1011,12 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
this.a((CrashReport) null); this.a((CrashReport) null);
} }
} catch (Throwable throwable) { } catch (Throwable throwable) {
@ -221,7 +217,7 @@ index 04eb2af28f9843ef7641f5464d2a043c696de864..d9ed9df3021dab1f5ee0a51215a00225
MinecraftServer.LOGGER.error("Encountered an unexpected exception", throwable); MinecraftServer.LOGGER.error("Encountered an unexpected exception", throwable);
// Spigot Start // Spigot Start
if ( throwable.getCause() != null ) if ( throwable.getCause() != null )
@@ -1002,14 +1047,14 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas @@ -1002,14 +1048,14 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
} catch (Throwable throwable1) { } catch (Throwable throwable1) {
MinecraftServer.LOGGER.error("Exception stopping the server", throwable1); MinecraftServer.LOGGER.error("Exception stopping the server", throwable1);
} finally { } finally {
@ -239,7 +235,7 @@ index 04eb2af28f9843ef7641f5464d2a043c696de864..d9ed9df3021dab1f5ee0a51215a00225
} }
} }
@@ -1065,6 +1110,12 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas @@ -1065,6 +1111,12 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
@Override @Override
protected TickTask postToMainThread(Runnable runnable) { protected TickTask postToMainThread(Runnable runnable) {
@ -252,7 +248,7 @@ index 04eb2af28f9843ef7641f5464d2a043c696de864..d9ed9df3021dab1f5ee0a51215a00225
return new TickTask(this.ticks, runnable); return new TickTask(this.ticks, runnable);
} }
@@ -1307,6 +1358,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas @@ -1307,6 +1359,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
try { try {
crashreport = CrashReport.a(throwable, "Exception ticking world"); crashreport = CrashReport.a(throwable, "Exception ticking world");
} catch (Throwable t) { } catch (Throwable t) {
@ -260,7 +256,7 @@ index 04eb2af28f9843ef7641f5464d2a043c696de864..d9ed9df3021dab1f5ee0a51215a00225
throw new RuntimeException("Error generating crash report", t); throw new RuntimeException("Error generating crash report", t);
} }
// Spigot End // Spigot End
@@ -1757,7 +1809,8 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas @@ -1757,7 +1810,8 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
this.resourcePackRepository.a(collection); this.resourcePackRepository.a(collection);
this.saveData.a(a(this.resourcePackRepository)); this.saveData.a(a(this.resourcePackRepository));
datapackresources.i(); datapackresources.i();
@ -271,7 +267,7 @@ index 04eb2af28f9843ef7641f5464d2a043c696de864..d9ed9df3021dab1f5ee0a51215a00225
this.customFunctionData.a(this.dataPackResources.a()); this.customFunctionData.a(this.dataPackResources.a());
this.ak.a(this.dataPackResources.h()); this.ak.a(this.dataPackResources.h());
diff --git a/src/main/java/net/minecraft/server/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java diff --git a/src/main/java/net/minecraft/server/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java
index c31e7c977194c953a47f5f04d9f90442a88e2db3..6e7754588960a1e6ceacc8b4cfd8237a10e210bb 100644 index d95ef14f5a4babc8c8fff349baf6a9aa44edcc82..1fcf75b2ed3c8c1ca2e31f679fc7d507f963caf2 100644
--- a/src/main/java/net/minecraft/server/PlayerChunkMap.java --- a/src/main/java/net/minecraft/server/PlayerChunkMap.java
+++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java +++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java
@@ -486,6 +486,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d { @@ -486,6 +486,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {

View file

@ -44,10 +44,10 @@ index 9b89c0c8a3f1dada4e9b2aaeed0b92e56229b7ca..0c46297e6ff229538d77b2f481e4ab13
List<Entity> list = this.tracker.getPassengers(); List<Entity> list = this.tracker.getPassengers();
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index d9ed9df3021dab1f5ee0a51215a002253ac1e34c..b32d41fac5f855e302469209f368c3674b849fe3 100644 index fb65978d783a91b341658e0ebe393ab77153a0d9..752ef8c1f99c6ef224e4df0c544f7894c2b3d3ab 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java --- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -1526,6 +1526,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas @@ -1527,6 +1527,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
} }
} }

View file

@ -10,10 +10,10 @@ Adds a 5 second grace period for any async tasks to finish and warns
if any are still running after that delay just as reload does. if any are still running after that delay just as reload does.
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index b32d41fac5f855e302469209f368c3674b849fe3..7c1c929819c450f853c91618b2853fcb424caa22 100644 index 752ef8c1f99c6ef224e4df0c544f7894c2b3d3ab..aaea027a3c3f6797e2c763f0ae7159e2d431049e 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java --- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -772,6 +772,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas @@ -773,6 +773,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
// CraftBukkit start // CraftBukkit start
if (this.server != null) { if (this.server != null) {
this.server.disablePlugins(); this.server.disablePlugins();

View file

@ -39,10 +39,10 @@ index 4c561181a977fd0244325880bb6a8cd6a54dcacc..8b2755a3b95e472e884976195d1d3551
@Override @Override
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 7c1c929819c450f853c91618b2853fcb424caa22..26f230a801bd8efa5f8b61dee53fe7b1435f906b 100644 index aaea027a3c3f6797e2c763f0ae7159e2d431049e..67a6fc68c6611dab2a3617d5605d7a9e7d9bee2a 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java --- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -1519,11 +1519,14 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas @@ -1520,11 +1520,14 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
this.H = keypair; this.H = keypair;
} }
@ -63,7 +63,7 @@ index 7c1c929819c450f853c91618b2853fcb424caa22..26f230a801bd8efa5f8b61dee53fe7b1
} }
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
index 4a99a05ef2d01383553e59833a8723f5364168ed..cf83059fec9f11df992827f0c0249243caa9ac33 100644 index 999ab59d1efc095029baea4d4101eb9b2f80347f..1cc16c20ca03902c3e871a7ec19fab442253da27 100644
--- a/src/main/java/net/minecraft/server/PlayerConnection.java --- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java +++ b/src/main/java/net/minecraft/server/PlayerConnection.java
@@ -2780,7 +2780,7 @@ public class PlayerConnection implements PacketListenerPlayIn { @@ -2780,7 +2780,7 @@ public class PlayerConnection implements PacketListenerPlayIn {