From 43ab2669d768f1a2cfe32418cd275d110691af05 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 27 Aug 2016 15:51:54 +1000 Subject: [PATCH] SPIGOT-2634: Concurrency issue in FileIOThread --- nms-patches/ChunkRegionLoader.patch | 43 +++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/nms-patches/ChunkRegionLoader.patch b/nms-patches/ChunkRegionLoader.patch index 55025dfe1e..a2335fa26f 100644 --- a/nms-patches/ChunkRegionLoader.patch +++ b/nms-patches/ChunkRegionLoader.patch @@ -90,7 +90,38 @@ } } } -@@ -131,10 +179,14 @@ +@@ -98,20 +146,27 @@ + } + + public boolean c() { +- if (this.b.isEmpty()) { ++ // CraftBukkit start ++ Iterator> iter = this.b.entrySet().iterator(); ++ if (!iter.hasNext()) { ++ // CraftBukkit end + if (this.f) { + ChunkRegionLoader.a.info("ThreadedAnvilChunkStorage ({}): All chunks are saved", new Object[] { this.d.getName()}); + } + + return false; + } else { +- ChunkCoordIntPair chunkcoordintpair = (ChunkCoordIntPair) this.b.keySet().iterator().next(); ++ // CraftBukkit start ++ Map.Entry entry = iter.next(); ++ iter.remove(); // Pop single entry ++ ChunkCoordIntPair chunkcoordintpair = entry.getKey(); ++ // CraftBukkit end + + boolean flag; + + try { + this.c.add(chunkcoordintpair); +- NBTTagCompound nbttagcompound = (NBTTagCompound) this.b.remove(chunkcoordintpair); ++ NBTTagCompound nbttagcompound = (NBTTagCompound) entry.getValue(); // CraftBukkit + + if (nbttagcompound != null) { + try { +@@ -131,10 +186,14 @@ } private void b(ChunkCoordIntPair chunkcoordintpair, NBTTagCompound nbttagcompound) throws IOException { @@ -106,7 +137,7 @@ } public void b(World world, Chunk chunk) throws IOException {} -@@ -149,6 +201,7 @@ +@@ -149,6 +208,7 @@ if (this.c()) { continue; } @@ -114,7 +145,7 @@ } } finally { this.f = false; -@@ -326,6 +379,13 @@ +@@ -326,6 +386,13 @@ chunk.a(nbttagcompound.getByteArray("Biomes")); } @@ -128,7 +159,7 @@ NBTTagList nbttaglist1 = nbttagcompound.getList("Entities", 10); if (nbttaglist1 != null) { -@@ -369,7 +429,7 @@ +@@ -369,7 +436,7 @@ } } @@ -137,7 +168,7 @@ } @Nullable -@@ -397,14 +457,20 @@ +@@ -397,14 +464,20 @@ } @Nullable @@ -159,7 +190,7 @@ return null; } else { if (nbttagcompound.hasKeyOfType("Passengers", 9)) { -@@ -433,8 +499,14 @@ +@@ -433,8 +506,14 @@ } }