2020-05-06 09:48:49 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2017-10-15 13:00:42 +00:00
From: Shane Freeder <theboyetronic@gmail.com>
Date: Sun, 15 Oct 2017 00:29:07 +0100
2017-12-24 13:44:41 +00:00
Subject: [PATCH] revert serverside behavior of keepalives
2017-10-15 13:00:42 +00:00
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.
2017-12-24 13:44:41 +00:00
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.
2017-10-15 13:00:42 +00:00
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
2020-06-30 05:20:29 +00:00
index 1d28b2b382877bb24958f28739e90bacfe8b9a94..76cd3ea9512f4355a055d9c683d939680dc5a1b7 100644
2017-10-15 13:00:42 +00:00
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
2019-05-06 02:58:04 +00:00
@@ -70,7 +70,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
2018-03-31 14:27:41 +00:00
private final MinecraftServer minecraftServer;
public EntityPlayer player;
private int e;
2018-12-17 05:18:06 +00:00
- private long lastKeepAlive; private void setLastPing(long lastPing) { this.lastKeepAlive = lastPing;}; private long getLastPing() { return this.lastKeepAlive;}; // Paper - OBFHELPER
+ private long lastKeepAlive = SystemUtils.getMonotonicMillis(); private void setLastPing(long lastPing) { this.lastKeepAlive = lastPing;}; private long getLastPing() { return this.lastKeepAlive;}; // Paper - OBFHELPER
private boolean awaitingKeepAlive; private void setPendingPing(boolean isPending) { this.awaitingKeepAlive = isPending;}; private boolean isPendingPing() { return this.awaitingKeepAlive;}; // Paper - OBFHELPER
2018-03-31 14:27:41 +00:00
private long h; private void setKeepAliveID(long keepAliveID) { this.h = keepAliveID;}; private long getKeepAliveID() {return this.h; }; // Paper - OBFHELPER
// CraftBukkit start - multithreaded fields
2019-05-06 02:58:04 +00:00
@@ -101,6 +101,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
2018-07-18 00:08:13 +00:00
private int E;
2017-12-24 13:44:41 +00:00
private int receivedMovePackets;
private int processedMovePackets;
+ private static final long KEEPALIVE_LIMIT = Long.getLong("paper.playerconnection.keepalive", 30) * 1000; // Paper - provide property to set keepalive limit
public PlayerConnection(MinecraftServer minecraftserver, NetworkManager networkmanager, EntityPlayer entityplayer) {
this.minecraftServer = minecraftserver;
2020-06-25 13:11:48 +00:00
@@ -182,18 +183,25 @@ public class PlayerConnection implements PacketListenerPlayIn {
2017-10-15 13:00:42 +00:00
}
2019-04-27 23:23:53 +00:00
this.minecraftServer.getMethodProfiler().enter("keepAlive");
2018-12-17 05:18:06 +00:00
- long i = SystemUtils.getMonotonicMillis();
2019-05-14 04:17:05 +00:00
-
- if (i - this.lastKeepAlive >= 25000L) { // CraftBukkit
- if (this.awaitingKeepAlive) {
2020-06-25 13:11:48 +00:00
- this.disconnect(new ChatMessage("disconnect.timeout"));
- } else {
- this.awaitingKeepAlive = true;
- this.lastKeepAlive = i;
- this.h = i;
- this.sendPacket(new PacketPlayOutKeepAlive(this.h));
2017-10-15 13:00:42 +00: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
2018-12-17 05:18:06 +00:00
+ long currentTime = SystemUtils.getMonotonicMillis();
2017-10-15 13:00:42 +00:00
+ long elapsedTime = currentTime - this.getLastPing();
2018-07-18 00:08:13 +00:00
+
2017-10-15 13:00:42 +00:00
+ if (this.isPendingPing()) {
2017-12-24 13:44:41 +00:00
+ if (!this.processedDisconnect && elapsedTime >= KEEPALIVE_LIMIT) { // check keepalive limit, don't fire if already disconnected
2017-10-15 13:00:42 +00:00
+ PlayerConnection.LOGGER.warn("{} was kicked due to keepalive timeout!", this.player.getName()); // more info
2020-06-25 13:11:48 +00:00
+ this.disconnect(new ChatMessage("disconnect.timeout", new Object[0]));
2017-10-15 13:00:42 +00:00
+ }
+ } else {
+ if (elapsedTime >= 15000L) { // 15 seconds
+ this.setPendingPing(true);
+ this.setLastPing(currentTime);
+ this.setKeepAliveID(currentTime);
+ this.sendPacket(new PacketPlayOutKeepAlive(this.getKeepAliveID()));
}
}
+ // Paper end
2019-04-27 23:23:53 +00:00
this.minecraftServer.getMethodProfiler().exit();
2017-10-15 13:00:42 +00:00
// CraftBukkit start