2019-04-23 12:47:07 +08:00
From c1b75aa5e3a7cdc24024773406bb873d6e33943f Mon Sep 17 00:00:00 2001
2016-03-18 13:35:26 +08:00
From: Aikar <aikar@aikar.co>
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/RegionFile.java b/src/main/java/net/minecraft/server/RegionFile.java
2019-02-22 11:41:20 +08:00
index 0f1c74dd33..9626396745 100644
2016-03-18 13:35:26 +08:00
--- a/src/main/java/net/minecraft/server/RegionFile.java
+++ b/src/main/java/net/minecraft/server/RegionFile.java
2019-02-22 11:41:20 +08:00
@@ -276,8 +276,7 @@ public class RegionFile {
2016-03-18 13:35:26 +08:00
2019-01-01 11:15:55 +08:00
this.b(i, j, (int) (SystemUtils.getTimeMillis() / 1000L));
2016-03-18 13:35:26 +08:00
} catch (IOException ioexception) {
- ioexception.printStackTrace();
- ServerInternalException.reportInternalException(ioexception); // Paper
2019-01-07 01:15:21 +08:00
+ com.destroystokyo.paper.util.SneakyThrow.sneaky(ioexception); // Paper - we want the upper try/catch to retry this
2016-03-18 13:35:26 +08:00
}
}
2018-08-27 02:11:49 +08:00
diff --git a/src/main/java/net/minecraft/server/RegionFileCache.java b/src/main/java/net/minecraft/server/RegionFileCache.java
2019-02-22 11:41:20 +08:00
index e507a996f1..5dbd1d517a 100644
2018-08-27 02:11:49 +08:00
--- a/src/main/java/net/minecraft/server/RegionFileCache.java
+++ b/src/main/java/net/minecraft/server/RegionFileCache.java
@@ -95,11 +95,29 @@ public class RegionFileCache {
@Nullable
public static synchronized void write(File file, int i, int j, NBTTagCompound nbttagcompound) throws IOException {
+ int attempts = 0; Exception laste = null; while (attempts++ < 5) { try { // Paper
RegionFile regionfile = a(file, i, j);
DataOutputStream dataoutputstream = regionfile.c(i & 31, j & 31);
NBTCompressedStreamTools.a(nbttagcompound, (java.io.DataOutput) dataoutputstream);
dataoutputstream.close();
+ // Paper start
+ laste = null; break; // Paper
+ } catch (Exception exception) {
+ //ChunkRegionLoader.a.error("Failed to save chunk", exception); // Paper
+ laste = exception; // Paper
+ }
+ try {
+ Thread.sleep(10);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ if (laste != null) {
+ com.destroystokyo.paper.exception.ServerInternalException.reportInternalException(laste);
+ MinecraftServer.LOGGER.error("Failed to save chunk", laste);
+ }
+ // Paper end
}
public static synchronized boolean chunkExists(File file, int i, int j) {
2016-03-18 13:35:26 +08:00
--
2019-04-23 12:47:07 +08:00
2.21.0
2016-03-18 13:35:26 +08:00