From fa69c791607dbb0959a66f6187cff5eb8f328a1f Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Thu, 14 Jan 2021 15:42:38 +0000 Subject: [PATCH] lock when editing the chunks cache in SingletThreadQueueExtent - Long2ObjectLinkedOpenHashMap is not thread-safe and should not be used from multiple threads at once - Fixes #851 --- .../beta/implementation/queue/SingleThreadQueueExtent.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/SingleThreadQueueExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/SingleThreadQueueExtent.java index 5f03b4cab..da9a517ff 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/SingleThreadQueueExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/SingleThreadQueueExtent.java @@ -114,7 +114,9 @@ public class SingleThreadQueueExtent extends ExtentBatchProcessorHolder implemen for (IChunk chunk : this.chunks.values()) { chunk.recycle(); } + getChunkLock.lock(); this.chunks.clear(); + getChunkLock.unlock(); } this.enabledQueue = true; this.lastChunk = null; @@ -163,7 +165,9 @@ public class SingleThreadQueueExtent extends ExtentBatchProcessorHolder implemen lastChunk = null; } final long index = MathMan.pairInt(chunk.getX(), chunk.getZ()); + getChunkLock.lock(); chunks.remove(index, chunk); + getChunkLock.unlock(); V future = submitUnchecked(chunk); submissions.add(future); return future; @@ -374,7 +378,9 @@ public class SingleThreadQueueExtent extends ExtentBatchProcessorHolder implemen } } } + getChunkLock.lock(); chunks.clear(); + getChunkLock.unlock(); } pollSubmissions(0, true); }