From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Aikar 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 9623a7bac79af37016ba5a5b37d4ef0b3dcb7312..f3d169436ce05f1c56599cfe15a56671b7d13516 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 @@ -275,7 +275,7 @@ public class RegionFile implements AutoCloseable { return true; } } catch (IOException ioexception) { - 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 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 2b6ba2e30c9a4682d6deb2ab750d6923ad8469e4..fa592d5db10dbd4824de74658655ef61230ed431 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 @@ -209,6 +209,7 @@ public class RegionFileStorage implements AutoCloseable { } // Paper end - rewrite chunk system try { // Paper + int attempts = 0; Exception laste = null; while (attempts++ < 5) { try { // Paper - Chunk save reattempt if (nbt == null) { regionfile.clear(pos); @@ -233,7 +234,18 @@ public class RegionFileStorage implements AutoCloseable { dataoutputstream.close(); } } + // Paper start - Chunk save reattempt + 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 " + pos, laste); + } + // Paper end - Chunk save reattempt } finally { // Paper start regionfile.fileLock.unlock(); } // Paper end