2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Shane Freeder <theboyetronic@gmail.com>
Date: Sun, 15 Oct 2017 00:29:07 +0100
Subject: [PATCH] revert serverside behavior of keepalives
This patch intends to bump up the time that a client has to reply to the
server back to 30 seconds as per pre 1.12.2, which allowed clients
more than enough time to reply potentially allowing them to be less
tempermental due to lag spikes on the network thread, e.g. that caused
by plugins that are interacting with netty.
We also add a system property to allow people to tweak how long the server
will wait for a reply. There is a compromise here between lower and higher
values, lower values will mean that dead connections can be closed sooner,
whereas higher values will make this less sensitive to issues such as spikes
from networking or during connections flood of chunk packets on slower clients,
at the cost of dead connections being kept open for longer.
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2023-06-21 15:36:14 +02:00
index 95256c095626f429315b80df86876b18112989bc..575ecae47633e7a30c8bca57d686dcfc0b31a0df 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2023-05-12 13:10:08 +02:00
@@ -259,7 +259,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2021-06-11 14:02:28 +02:00
public ServerPlayer player;
private int tickCount;
2022-06-07 22:45:38 +02:00
private int ackBlockChangesUpTo = -1;
- private long keepAliveTime;
2021-06-12 14:58:17 +02:00
+ private long keepAliveTime = Util.getMillis();
2022-06-07 22:45:38 +02:00
private boolean keepAlivePending;
private long keepAliveChallenge;
2021-06-11 14:02:28 +02:00
// CraftBukkit start - multithreaded fields
2023-05-12 13:10:08 +02:00
@@ -297,6 +297,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2022-12-07 19:52:24 +01:00
private final LastSeenMessagesValidator lastSeenMessages;
private final MessageSignatureCache messageSignatureCache;
2022-07-27 21:49:24 +02:00
private final FutureChain chatMessageChain;
2021-06-11 14:02:28 +02:00
+ private static final long KEEPALIVE_LIMIT = Long.getLong("paper.playerconnection.keepalive", 30) * 1000; // Paper - provide property to set keepalive limit
public ServerGamePacketListenerImpl(MinecraftServer server, Connection connection, ServerPlayer player) {
2022-06-07 22:45:38 +02:00
this.lastChatTimeStamp = new AtomicReference(Instant.EPOCH);
2023-05-12 13:10:08 +02:00
@@ -388,18 +389,25 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2021-06-11 14:02:28 +02:00
}
this.server.getProfiler().push("keepAlive");
- long i = Util.getMillis();
2023-06-07 21:37:42 +02:00
-
2022-07-27 21:49:24 +02:00
- if (i - this.keepAliveTime >= 25000L) { // CraftBukkit
- if (this.keepAlivePending) {
- this.disconnect(Component.translatable("disconnect.timeout"));
- } else {
2023-06-07 21:37:42 +02:00
+ // Paper Start - give clients a longer time to respond to pings as per pre 1.12.2 timings
+ // This should effectively place the keepalive handling back to "as it was" before 1.12.2
+ long currentTime = Util.getMillis();
+ long elapsedTime = currentTime - this.keepAliveTime;
+
2021-06-12 14:58:17 +02:00
+ if (this.keepAlivePending) {
2021-06-11 14:02:28 +02:00
+ if (!this.processedDisconnect && elapsedTime >= KEEPALIVE_LIMIT) { // check keepalive limit, don't fire if already disconnected
+ ServerGamePacketListenerImpl.LOGGER.warn("{} was kicked due to keepalive timeout!", this.player.getScoreboardName()); // more info
2022-06-07 22:45:38 +02:00
+ this.disconnect(Component.translatable("disconnect.timeout", new Object[0]));
2021-06-11 14:02:28 +02:00
+ }
+ } else {
+ if (elapsedTime >= 15000L) { // 15 seconds
2021-06-12 14:58:17 +02:00
this.keepAlivePending = true;
- this.keepAliveTime = i;
- this.keepAliveChallenge = i;
+ this.keepAliveTime = currentTime;
+ this.keepAliveChallenge = currentTime;
this.send(new ClientboundKeepAlivePacket(this.keepAliveChallenge));
2021-06-11 14:02:28 +02:00
}
}
+ // Paper end
this.server.getProfiler().pop();
// CraftBukkit start