aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0403-Fix-Chunk-Post-Processing-deadlock-risk.patch
diff options
context:
space:
mode:
authorJake Potrebic <[email protected]>2022-02-28 19:25:13 -0800
committerJason Penilla <[email protected]>2022-02-28 22:52:39 -0700
commitcc45a355a4e76f749e4618a61b233f40a3c05180 (patch)
tree445eb9887060005896841d58d5c6bfb1f36ff62e /patches/server/0403-Fix-Chunk-Post-Processing-deadlock-risk.patch
parent5071d50207620641e8c4bbc579dd9136ad6a2566 (diff)
downloadPaper-cc45a355a4e76f749e4618a61b233f40a3c05180.tar.gz
Paper-cc45a355a4e76f749e4618a61b233f40a3c05180.zip
move decompile fixes to start of git history
Diffstat (limited to 'patches/server/0403-Fix-Chunk-Post-Processing-deadlock-risk.patch')
-rw-r--r--patches/server/0403-Fix-Chunk-Post-Processing-deadlock-risk.patch59
1 files changed, 59 insertions, 0 deletions
diff --git a/patches/server/0403-Fix-Chunk-Post-Processing-deadlock-risk.patch b/patches/server/0403-Fix-Chunk-Post-Processing-deadlock-risk.patch
new file mode 100644
index 0000000000..798b404277
--- /dev/null
+++ b/patches/server/0403-Fix-Chunk-Post-Processing-deadlock-risk.patch
@@ -0,0 +1,59 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Aikar <[email protected]>
+Date: Sat, 18 Apr 2020 04:36:11 -0400
+Subject: [PATCH] Fix Chunk Post Processing deadlock risk
+
+See: https://gist.github.com/aikar/dd22bbd2a3d78a2fd3d92e95e9f28dc6
+
+as part of post processing a chunk, we can call ChunkConverter.
+
+ChunkConverter then kicks off major physics updates, and when blocks
+that have connections across chunk boundries occur, a recursive risk
+can occur where A updates a block that triggers a physics request.
+
+That physics request may trigger a chunk request, that then enqueues
+a task into the Mailbox ChunkTaskQueueSorter.
+
+If anything requests that same chunk that is in the middle of conversion,
+it's mailbox queue is going to be held up, so the subsequent chunk request
+will be unable to proceed.
+
+We delay post processing of Chunk.A() 1 "pass" by re stuffing it back into
+the executor so that the mailbox ChunkQueue is now considered empty.
+
+This successfully fixed a reoccurring and highly reproduceable crash
+for heightmaps.
+
+diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
+index 7e3f7b69fc7a608dd82b471d832cc401a77f0738..86a06c7ee3b92fbff1e21ad36b6034d892cd0c01 100644
+--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
++++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
+@@ -178,6 +178,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
+ };
+ // CraftBukkit end
+
++ final CallbackExecutor chunkLoadConversionCallbackExecutor = new CallbackExecutor(); // Paper
+ // Paper start - distance maps
+ private final com.destroystokyo.paper.util.misc.PooledLinkedHashSets<ServerPlayer> pooledLinkedPlayerHashSets = new com.destroystokyo.paper.util.misc.PooledLinkedHashSets<>();
+
+@@ -1030,7 +1031,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
+ });
+ });
+ }, (runnable) -> {
+- this.mainThreadMailbox.tell(ChunkTaskPriorityQueueSorter.message(holder, runnable));
++ this.mainThreadMailbox.tell(ChunkTaskPriorityQueueSorter.message(holder, () -> ChunkMap.this.chunkLoadConversionCallbackExecutor.execute(runnable))); // Paper - delay running Chunk post processing until outside of the sorter to prevent a deadlock scenario when post processing causes another chunk request.
+ });
+ return completablefuture1;
+ }
+diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
+index cf56b2ed508352205ef6ec71519b0626aa698987..1b6fb81079d3ad5d3c33be67a1c05111f9dd5f2d 100644
+--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
++++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
+@@ -1141,6 +1141,7 @@ public class ServerChunkCache extends ChunkSource {
+ return super.pollTask() || execChunkTask; // Paper
+ }
+ } finally {
++ chunkMap.chunkLoadConversionCallbackExecutor.run(); // Paper - Add chunk load conversion callback executor to prevent deadlock due to recursion in the chunk task queue sorter
+ chunkMap.callbackExecutor.run();
+ }
+ // CraftBukkit end