aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0060-Chunk-Save-Reattempt.patch
blob: 82a269b2204d6b44edf2e366a545d343589befa4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
index fbf5f01a9a7968194fc85589ca7f9fa328da4881..2d74ab966a1291895b6248a67a31fe4802b3773f 100644
--- a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java
@@ -274,7 +274,7 @@ public class RegionFile implements AutoCloseable {
                     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
index 8ba1c073387fa21a20bd42a873ec3cc314eae64e..eaf22cec54b512e0f57606f50627d5fe9b39bd5c 100644
--- a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
@@ -131,6 +131,7 @@ public class RegionFileStorage implements AutoCloseable {
 
     protected void write(ChunkPos pos, @Nullable CompoundTag nbt) throws IOException {
         RegionFile regionfile = this.getRegionFile(pos, false); // CraftBukkit
+        int attempts = 0; Exception laste = null; while (attempts++ < 5) { try { // Paper
 
         if (nbt == null) {
             regionfile.clear(pos);
@@ -156,6 +157,18 @@ public class RegionFileStorage implements AutoCloseable {
             }
         }
 
+            // Paper start
+            return;
+        } catch (Exception ex)  {
+            laste = ex;
+        }
+        }
+
+        if (laste != null) {
+            com.destroystokyo.paper.exception.ServerInternalException.reportInternalException(laste);
+            net.minecraft.server.MinecraftServer.LOGGER.error("Failed to save chunk", laste);
+        }
+        // Paper end
     }
 
     public void close() throws IOException {