From 98b86017faefc853af2fc7a87f162c202e21c8d3 Mon Sep 17 00:00:00 2001 From: Aikar Date: Fri, 18 Mar 2016 01:35:26 -0400 Subject: [PATCH] Chunk Save Reattempt Sometimes a chunk region file is closed prematurely, resulting in a "Stream Closed" error on chunk saving. Ultimately there is a race condition that causes it, but re-trying the save will avoid the issue. Retry the save 5 times to try our best to avoid rollbacks due to chunk save failures. --- .../0084-Chunk-Save-Reattempt.patch | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Spigot-Server-Patches/0084-Chunk-Save-Reattempt.patch diff --git a/Spigot-Server-Patches/0084-Chunk-Save-Reattempt.patch b/Spigot-Server-Patches/0084-Chunk-Save-Reattempt.patch new file mode 100644 index 000000000..ae4dca4f1 --- /dev/null +++ b/Spigot-Server-Patches/0084-Chunk-Save-Reattempt.patch @@ -0,0 +1,46 @@ +From 798d650695eced24d570d3234da5daf0176aa1ab Mon Sep 17 00:00:00 2001 +From: Aikar +Date: Mon, 4 Mar 2013 23:46:10 -0500 +Subject: [PATCH] Chunk Save Reattempt + +We commonly have "Stream Closed" errors on chunk saving, so this code should re-try to save the chunk in the event of failure and hopefully prevent rollbacks. + +diff --git a/src/main/java/net/minecraft/server/ChunkRegionLoader.java b/src/main/java/net/minecraft/server/ChunkRegionLoader.java +index 336e780..7eb13f8 100644 +--- a/src/main/java/net/minecraft/server/ChunkRegionLoader.java ++++ b/src/main/java/net/minecraft/server/ChunkRegionLoader.java +@@ -170,11 +170,16 @@ public class ChunkRegionLoader implements IChunkLoader, IAsyncChunkSaver { + NBTTagCompound nbttagcompound = chunk.compound; // Paper - Chunk queue improvements + + if (nbttagcompound != null) { ++ int attempts = 0; Exception laste = null; while (attempts++ < 5) { // Paper + try { + this.b(chunkcoordintpair, nbttagcompound); ++ laste = null; break; // Paper + } catch (Exception exception) { +- ChunkRegionLoader.a.error("Failed to save chunk", exception); ++ //ChunkRegionLoader.a.error("Failed to save chunk", exception); // Paper ++ laste = exception; // Paper + } ++ try {Thread.sleep(10);} catch (InterruptedException e) {e.printStackTrace();} } // Paper ++ if (laste != null) { com.destroystokyo.paper.exception.ServerInternalException.reportInternalException(laste); laste.printStackTrace(); } // Paper + } + synchronized (lock) { if (this.b.get(chunkcoordintpair) == nbttagcompound) { this.b.remove(chunkcoordintpair); } }// Paper - This will not equal if a newer version is still pending + +diff --git a/src/main/java/net/minecraft/server/RegionFile.java b/src/main/java/net/minecraft/server/RegionFile.java +index aa74c87..9d07be1 100644 +--- a/src/main/java/net/minecraft/server/RegionFile.java ++++ b/src/main/java/net/minecraft/server/RegionFile.java +@@ -248,8 +248,7 @@ public class RegionFile { + + this.b(i, j, (int) (MinecraftServer.av() / 1000L)); + } catch (IOException ioexception) { +- ioexception.printStackTrace(); +- ServerInternalException.reportInternalException(ioexception); // Paper ++ org.spigotmc.SneakyThrow.sneaky(ioexception); // Paper - we want the upper try/catch to retry this + } + + } +-- +2.7.3 +