From 903f4261245e27fef88cf7084e91eae0c3dcd88a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=A7=80=20Harold?= <55301634+ZECHEESELORD@users.noreply.github.com> Date: Fri, 20 Mar 2026 01:19:00 -0400 Subject: [PATCH 1/2] Reset pending keepalive state on listener handoff --- .../0024-Improve-keepalive-ping-system.patch | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/paper-server/patches/features/0024-Improve-keepalive-ping-system.patch b/paper-server/patches/features/0024-Improve-keepalive-ping-system.patch index f046496ff6a4..089ab0fbe71a 100644 --- a/paper-server/patches/features/0024-Improve-keepalive-ping-system.patch +++ b/paper-server/patches/features/0024-Improve-keepalive-ping-system.patch @@ -16,7 +16,7 @@ new file mode 100644 index 0000000000000000000000000000000000000000..4a2520f554c2ee74faf86d7c93baccf0f391a6b3 --- /dev/null +++ b/io/papermc/paper/util/KeepAlive.java -@@ -0,0 +1,67 @@ +@@ -0,0 +1,84 @@ +package io.papermc.paper.util; + +public class KeepAlive { @@ -34,6 +34,14 @@ index 0000000000000000000000000000000000000000..4a2520f554c2ee74faf86d7c93baccf0 + public final PingCalculator pingCalculator1m = new PingCalculator(java.util.concurrent.TimeUnit.MINUTES.toNanos(1L)); + public final PingCalculator pingCalculator5s = new PingCalculator(java.util.concurrent.TimeUnit.SECONDS.toNanos(5L)); + ++ public KeepAlive copyForListenerHandoff() { ++ KeepAlive copy = new KeepAlive(); ++ copy.lastKeepAliveTx = this.lastKeepAliveTx; ++ copy.pingCalculator1m.copyFrom(this.pingCalculator1m); ++ copy.pingCalculator5s.copyFrom(this.pingCalculator5s); ++ return copy; ++ } ++ + public static final class PingCalculator { + + private final long intervalNS; @@ -47,6 +55,15 @@ index 0000000000000000000000000000000000000000..4a2520f554c2ee74faf86d7c93baccf0 + this.intervalNS = intervalNS; + } + ++ private void copyFrom(PingCalculator other) { ++ for (KeepAliveResponse response : other.responses) { ++ this.responses.add(response); ++ } ++ this.timeSumNS = other.timeSumNS; ++ this.timeSumCount = other.timeSumCount; ++ this.lastAverageNS = other.lastAverageNS; ++ } ++ + public void update(KeepAliveResponse response) { + long currTime = response.txTimeNS; + @@ -223,11 +240,19 @@ index 079ab378920c0e52ef4e42ef20b37bd389f40870..b8a4b4cc02a2fc6b70f4b840796eed50 } } -@@ -427,6 +460,6 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack +@@ -427,6 +460,13 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack } protected CommonListenerCookie createCookie(ClientInformation clientInformation) { - return new CommonListenerCookie(this.playerProfile(), this.latency, clientInformation, this.transferred, this.playerBrand, this.pluginMessagerChannels); // Paper -+ return new CommonListenerCookie(this.playerProfile(), this.latency, clientInformation, this.transferred, this.playerBrand, this.pluginMessagerChannels, this.keepAlive); // Paper ++ return new CommonListenerCookie( ++ this.playerProfile(), ++ this.latency, ++ clientInformation, ++ this.transferred, ++ this.playerBrand, ++ this.pluginMessagerChannels, ++ this.keepAlive.copyForListenerHandoff() ++ ); // Paper - listener handoff should reset pending keepalive expectations } } From 3343c9798c5f68a5eeff87de35993a87cf095eb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=A7=80=20Harold?= <55301634+ZECHEESELORD@users.noreply.github.com> Date: Sat, 21 Mar 2026 17:05:56 -0400 Subject: [PATCH 2/2] fix patch headers --- .../features/0024-Improve-keepalive-ping-system.patch | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/paper-server/patches/features/0024-Improve-keepalive-ping-system.patch b/paper-server/patches/features/0024-Improve-keepalive-ping-system.patch index 089ab0fbe71a..7c9ffecdb454 100644 --- a/paper-server/patches/features/0024-Improve-keepalive-ping-system.patch +++ b/paper-server/patches/features/0024-Improve-keepalive-ping-system.patch @@ -13,7 +13,7 @@ average over the last 5 seconds of keepalive transactions. diff --git a/io/papermc/paper/util/KeepAlive.java b/io/papermc/paper/util/KeepAlive.java new file mode 100644 -index 0000000000000000000000000000000000000000..4a2520f554c2ee74faf86d7c93baccf0f391a6b3 +index 0000000000000000000000000000000000000000..66d6af2833d76af28fbeb2ce70c194a559572460 --- /dev/null +++ b/io/papermc/paper/util/KeepAlive.java @@ -0,0 +1,84 @@ @@ -117,7 +117,7 @@ index 21d50675bfe90c2276890779eb23de58ac915b9a..7be34e37562875313b8e43357921b5fe } } diff --git a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java -index 079ab378920c0e52ef4e42ef20b37bd389f40870..b8a4b4cc02a2fc6b70f4b840796eed501aad6239 100644 +index 079ab378920c0e52ef4e42ef20b37bd389f40870..dc9020f210c21a626c948d013cc6c972cbc093f3 100644 --- a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java +++ b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java @@ -39,12 +39,13 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack @@ -240,7 +240,7 @@ index 079ab378920c0e52ef4e42ef20b37bd389f40870..b8a4b4cc02a2fc6b70f4b840796eed50 } } -@@ -427,6 +460,13 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack +@@ -427,6 +460,14 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack } protected CommonListenerCookie createCookie(ClientInformation clientInformation) {