aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0062-Chunk-Save-Reattempt.patch
blob: 591975e7fbd6e80ae684e0338c3c03e9c88d708b (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
52
53
54
55
56
57
58
From 3e2785e893872375e49c0565c801df502bc1a616 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/server/RegionFile.java b/src/main/java/net/minecraft/server/RegionFile.java
index 0f1c74dd33..9626396745 100644
--- a/src/main/java/net/minecraft/server/RegionFile.java
+++ b/src/main/java/net/minecraft/server/RegionFile.java
@@ -276,8 +276,7 @@ public class RegionFile {
 
             this.b(i, j, (int) (SystemUtils.getTimeMillis() / 1000L));
         } catch (IOException ioexception) {
-            ioexception.printStackTrace();
-            ServerInternalException.reportInternalException(ioexception); // Paper
+            com.destroystokyo.paper.util.SneakyThrow.sneaky(ioexception); // Paper - we want the upper try/catch to retry this
         }
 
     }
diff --git a/src/main/java/net/minecraft/server/RegionFileCache.java b/src/main/java/net/minecraft/server/RegionFileCache.java
index e507a996f1..5dbd1d517a 100644
--- a/src/main/java/net/minecraft/server/RegionFileCache.java
+++ b/src/main/java/net/minecraft/server/RegionFileCache.java
@@ -95,11 +95,29 @@ public class RegionFileCache {
 
     @Nullable
     public static synchronized void write(File file, int i, int j, NBTTagCompound nbttagcompound) throws IOException {
+        int attempts = 0; Exception laste = null; while (attempts++ < 5) { try { // Paper
         RegionFile regionfile = a(file, i, j);
 
         DataOutputStream dataoutputstream = regionfile.c(i & 31, j & 31);
         NBTCompressedStreamTools.a(nbttagcompound, (java.io.DataOutput) dataoutputstream);
         dataoutputstream.close();
+        // Paper start
+            laste = null; break; // Paper
+            } catch (Exception exception) {
+                //ChunkRegionLoader.a.error("Failed to save chunk", exception); // Paper
+                laste = exception; // Paper
+            }
+            try {
+                Thread.sleep(10);
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+        }
+        if (laste != null) {
+            com.destroystokyo.paper.exception.ServerInternalException.reportInternalException(laste);
+            MinecraftServer.LOGGER.error("Failed to save chunk", laste);
+        }
+        // Paper end
     }
 
     public static synchronized boolean chunkExists(File file, int i, int j) {
-- 
2.20.1