From a6792af72a06ec3c2497480b173c15c76a94b430 Mon Sep 17 00:00:00 2001 From: Aikar Date: Sun, 16 Sep 2018 02:57:22 -0400 Subject: [PATCH] prevent crashes on expiring map desync, dont spam logs --- ...ix-major-memory-leaks-in-ExpiringMap.patch | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/Spigot-Server-Patches/Fix-major-memory-leaks-in-ExpiringMap.patch b/Spigot-Server-Patches/Fix-major-memory-leaks-in-ExpiringMap.patch index 3a68122d19..db46d64de3 100644 --- a/Spigot-Server-Patches/Fix-major-memory-leaks-in-ExpiringMap.patch +++ b/Spigot-Server-Patches/Fix-major-memory-leaks-in-ExpiringMap.patch @@ -11,7 +11,7 @@ not run on every manipulation, and instead to run clean once per tick per expiring map. diff --git a/src/main/java/net/minecraft/server/ExpiringMap.java b/src/main/java/net/minecraft/server/ExpiringMap.java -index 4006f5a69c..49021d29ee 100644 +index 4006f5a69c..08d41e8cf0 100644 --- a/src/main/java/net/minecraft/server/ExpiringMap.java +++ b/src/main/java/net/minecraft/server/ExpiringMap.java @@ -0,0 +0,0 @@ import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; @@ -116,10 +116,17 @@ index 4006f5a69c..49021d29ee 100644 + @Override + public T compute(Long aLong, BiFunction biFunction) { + setAccess(aLong); -+ return compute(aLong, biFunction); ++ return super.compute(aLong, biFunction); ++ } ++ ++ @Override ++ public synchronized void clear() { ++ ttl.clear(); ++ super.clear(); + } + + private boolean registered = false; ++ private boolean hasLeaked = false; + + // Break clean to its own method to be ticked + synchronized boolean clean() { @@ -141,11 +148,18 @@ index 4006f5a69c..49021d29ee 100644 } } - -+ if (this.ttl.size() != this.size()) { -+ MinecraftServer.LOGGER.error("WARNING: ExpiringMap desync - Memory leak risk!"); -+ for (Entry entry : this.long2ObjectEntrySet()) { -+ ttl.putIfAbsent(entry.getLongKey(), now); ++ int ttlSize = this.ttl.size(); ++ int thisSize = this.size(); ++ if (ttlSize != thisSize) { ++ if (!hasLeaked) { // log once ++ hasLeaked = true; ++ MinecraftServer.LOGGER.warn("WARNING: ExpiringMap desync (" + ttlSize + ":" + thisSize + ")- Memory leak risk! We will recover from this, but this means there is still a bug. Please do not open an issue about this. Mention it in Discord (we don't need everyone reporting the same thing)"); + } ++ try { ++ for (Entry entry : this.long2ObjectEntrySet()) { ++ ttl.putIfAbsent(entry.getLongKey(), now); ++ } ++ } catch (Exception e) { } // Ignore any como's + } + if (isEmpty()) { + registered = false;