2021-06-11 14:02:28 +02: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-09-01 18:51:59 +02:00
index 8adebb8408cc22ae7e9e89721645e5dd27a41cd8..038e2177182c94baa4af24f9111cf155ec342dfe 100644
2021-06-11 14:02:28 +02: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
2022-09-01 18:51:59 +02:00
@@ -275,7 +275,7 @@ public class RegionFile implements AutoCloseable {
2021-06-11 14:02:28 +02: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
2022-09-01 18:51:59 +02:00
index 6fa0bc18ab05b9fb05521f46c5dadb695f1ec05b..4210c43104de01200b149e13ffab09dea37c5caf 100644
2021-06-11 14:02:28 +02: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
2022-09-01 18:51:59 +02:00
@@ -163,6 +163,7 @@ public class RegionFileStorage implements AutoCloseable {
2021-06-12 02:57:04 +02:00
protected void write(ChunkPos pos, @Nullable CompoundTag nbt) throws IOException {
2022-09-01 18:51:59 +02:00
RegionFile regionfile = this.getRegionFile(pos, false, true); // CraftBukkit // Paper
try { // Paper
2021-06-11 14:02:28 +02:00
+ int attempts = 0; Exception laste = null; while (attempts++ < 5) { try { // Paper
2021-06-12 02:57:04 +02:00
if (nbt == null) {
regionfile.clear(pos);
2022-09-01 18:51:59 +02:00
@@ -187,7 +188,18 @@ public class RegionFileStorage implements AutoCloseable {
dataoutputstream.close();
2021-06-12 02:57:04 +02:00
}
2021-06-11 14:02:28 +02:00
}
2022-09-01 18:51:59 +02:00
+ // Paper start
+ return;
2021-06-11 14:02:28 +02:00
+ } catch (Exception ex) {
+ laste = ex;
+ }
+ }
2022-09-01 18:51:59 +02:00
2021-06-11 14:02:28 +02:00
+ if (laste != null) {
+ com.destroystokyo.paper.exception.ServerInternalException.reportInternalException(laste);
2022-09-01 18:51:59 +02:00
+ net.minecraft.server.MinecraftServer.LOGGER.error("Failed to save chunk " + pos, laste);
2021-06-11 14:02:28 +02:00
+ }
+ // Paper end
2022-09-01 18:51:59 +02:00
} finally { // Paper start
regionfile.fileLock.unlock();
} // Paper end