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-09-01 16:51:59 +00:00
index 8adebb8408cc22ae7e9e89721645e5dd27a41cd8..038e2177182c94baa4af24f9111cf155ec342dfe 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
2022-09-01 16:51:59 +00:00
@@ -275,7 +275,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
2022-09-26 08:02:51 +00:00
index 45cec71b3b2f9444d7be7e5bf9fab166b28ea34d..ece0fd4b51d124be232e24d08f115b9267cb21cb 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
2022-09-26 08:02:51 +00:00
@@ -167,6 +167,7 @@ public class RegionFileStorage implements AutoCloseable {
}
// Paper end - rewrite chunk system
2022-09-01 16:51:59 +00:00
try { // Paper
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);
2022-09-26 08:02:51 +00:00
@@ -191,7 +192,18 @@ public class RegionFileStorage implements AutoCloseable {
2022-09-01 16:51:59 +00:00
dataoutputstream.close();
2021-06-12 00:57:04 +00:00
}
2021-06-11 12:02:28 +00:00
}
2022-09-01 16:51:59 +00:00
+ // Paper start
+ return;
2021-06-11 12:02:28 +00:00
+ } catch (Exception ex) {
+ laste = ex;
+ }
+ }
2022-09-01 16:51:59 +00:00
2021-06-11 12:02:28 +00:00
+ if (laste != null) {
+ com.destroystokyo.paper.exception.ServerInternalException.reportInternalException(laste);
2022-09-01 16:51:59 +00:00
+ net.minecraft.server.MinecraftServer.LOGGER.error("Failed to save chunk " + pos, laste);
2021-06-11 12:02:28 +00:00
+ }
+ // Paper end
2022-09-01 16:51:59 +00:00
} finally { // Paper start
regionfile.fileLock.unlock();
} // Paper end