papermc/Spigot-Server-Patches/0059-Chunk-Save-Reattempt.patch

55 lines
2.3 KiB
Diff
Raw Normal View History

From 10153a917b3bdf01ba8935cf148e78722bf05e15 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 c2312a227c..cee1ea8f43 100644
--- a/src/main/java/net/minecraft/server/RegionFile.java
+++ b/src/main/java/net/minecraft/server/RegionFile.java
@@ -241,7 +241,7 @@ public class RegionFile implements AutoCloseable {
2019-12-11 02:43:21 +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/server/RegionFileCache.java b/src/main/java/net/minecraft/server/RegionFileCache.java
index a164aee880..fd46da95e0 100644
--- a/src/main/java/net/minecraft/server/RegionFileCache.java
+++ b/src/main/java/net/minecraft/server/RegionFileCache.java
@@ -85,6 +85,7 @@ public final class RegionFileCache implements AutoCloseable {
2019-04-26 01:24:00 +00:00
protected void write(ChunkCoordIntPair chunkcoordintpair, NBTTagCompound nbttagcompound) throws IOException {
2019-12-11 02:43:21 +00:00
RegionFile regionfile = this.getFile(chunkcoordintpair, false); // CraftBukkit
+ int attempts = 0; Exception laste = null; while (attempts++ < 5) { try { // Paper
2019-04-26 01:24:00 +00:00
DataOutputStream dataoutputstream = regionfile.c(chunkcoordintpair);
Throwable throwable = null;
2019-12-11 02:43:21 +00:00
@@ -108,6 +109,18 @@ public final class RegionFileCache implements AutoCloseable {
2019-04-26 01:24:00 +00:00
}
2019-05-07 15:26:37 +00:00
+ // Paper start
+ return;
2019-04-26 01:24:00 +00:00
+ } catch (Exception ex) {
+ laste = ex;
+ }
+ }
2019-04-26 01:24:00 +00:00
+
+ if (laste != null) {
+ com.destroystokyo.paper.exception.ServerInternalException.reportInternalException(laste);
+ MinecraftServer.LOGGER.error("Failed to save chunk", laste);
+ }
2019-05-07 15:26:37 +00:00
+ // Paper end
}
2019-04-26 01:24:00 +00:00
public void close() throws IOException {
--
2.26.2