2021-06-11 12:02:28 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
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/world/level/chunk/storage/RegionFile.java b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java
2022-03-01 03:25:13 +00:00
index fbf5f01a9a7968194fc85589ca7f9fa328da4881..2d74ab966a1291895b6248a67a31fe4802b3773f 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java
2021-11-23 12:15:10 +00:00
@@ -274,7 +274,7 @@ public class RegionFile implements AutoCloseable {
2021-06-11 12:02:28 +00:00
return true;
}
} catch (IOException ioexception) {
- com.destroystokyo.paper.exception.ServerInternalException.reportInternalException(ioexception); // Paper
+ com.destroystokyo.paper.util.SneakyThrow.sneaky(ioexception); // Paper - we want the upper try/catch to retry this
return false;
}
}
diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
2021-11-23 12:15:10 +00:00
index 8ba1c073387fa21a20bd42a873ec3cc314eae64e..eaf22cec54b512e0f57606f50627d5fe9b39bd5c 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
2021-11-23 12:15:10 +00:00
@@ -131,6 +131,7 @@ public class RegionFileStorage implements AutoCloseable {
2021-06-11 12:02:28 +00:00
2021-06-12 00:57:04 +00:00
protected void write(ChunkPos pos, @Nullable CompoundTag nbt) throws IOException {
2021-11-23 12:15:10 +00:00
RegionFile regionfile = this.getRegionFile(pos, false); // CraftBukkit
2021-06-11 12:02:28 +00:00
+ int attempts = 0; Exception laste = null; while (attempts++ < 5) { try { // Paper
2021-06-12 00:57:04 +00:00
if (nbt == null) {
regionfile.clear(pos);
2021-11-23 12:15:10 +00:00
@@ -156,6 +157,18 @@ public class RegionFileStorage implements AutoCloseable {
2021-06-12 00:57:04 +00:00
}
2021-06-11 12:02:28 +00:00
}
+ // Paper start
+ return;
+ } catch (Exception ex) {
+ laste = ex;
+ }
+ }
+
+ if (laste != null) {
+ com.destroystokyo.paper.exception.ServerInternalException.reportInternalException(laste);
2021-11-23 12:15:10 +00:00
+ net.minecraft.server.MinecraftServer.LOGGER.error("Failed to save chunk", laste);
2021-06-11 12:02:28 +00:00
+ }
+ // Paper end
}
public void close() throws IOException {