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
2024-01-23 14:34:17 +01:00
index 9623a7bac79af37016ba5a5b37d4ef0b3dcb7312..f3d169436ce05f1c56599cfe15a56671b7d13516 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
2023-09-22 22:13:57 +02:00
@@ -275,7 +275,7 @@ public class RegionFile implements AutoCloseable {
2021-06-11 14:02:28 +02:00
return true;
}
} catch (IOException ioexception) {
2024-01-23 14:34:17 +01:00
- com.destroystokyo.paper.exception.ServerInternalException.reportInternalException(ioexception); // Paper - ServerExceptionEvent
+ com.destroystokyo.paper.util.SneakyThrow.sneaky(ioexception); // Paper - Chunk save reattempt; we want the upper try/catch to retry this
2021-06-11 14:02:28 +02:00
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
2024-01-23 14:34:17 +01:00
index 2b6ba2e30c9a4682d6deb2ab750d6923ad8469e4..fa592d5db10dbd4824de74658655ef61230ed431 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
2023-09-22 22:13:57 +02:00
@@ -209,6 +209,7 @@ public class RegionFileStorage implements AutoCloseable {
}
// Paper end - rewrite chunk system
try { // Paper
2024-01-23 14:34:17 +01:00
+ int attempts = 0; Exception laste = null; while (attempts++ < 5) { try { // Paper - Chunk save reattempt
2021-06-11 14:02:28 +02:00
2021-06-12 02:57:04 +02:00
if (nbt == null) {
regionfile.clear(pos);
2023-09-22 22:13:57 +02:00
@@ -233,7 +234,18 @@ public class RegionFileStorage implements AutoCloseable {
2022-09-01 18:51:59 +02:00
dataoutputstream.close();
2021-06-12 02:57:04 +02:00
}
2021-06-11 14:02:28 +02:00
}
2024-01-23 14:34:17 +01:00
+ // Paper start - Chunk save reattempt
2022-09-01 18:51:59 +02:00
+ 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
+ }
2024-01-23 14:34:17 +01:00
+ // Paper end - Chunk save reattempt
2023-09-22 22:13:57 +02:00
} finally { // Paper start
regionfile.fileLock.unlock();
} // Paper end