2018-01-16 04:13:17 +01:00
From 02abc033533f70ef3165a97bfda3f5c2fa58633a Mon Sep 17 00:00:00 2001
2017-10-15 15:00:42 +02:00
From: Shane Freeder <theboyetronic@gmail.com>
Date: Sun, 15 Oct 2017 00:29:07 +0100
2017-12-24 14:44:41 +01:00
Subject: [PATCH] revert serverside behavior of keepalives
2017-10-15 15:00:42 +02: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 14:44:41 +01: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 15:00:42 +02:00
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
2018-01-16 04:13:17 +01:00
index a92bf8967..d0ab87d0f 100644
2017-10-15 15:00:42 +02:00
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
2017-12-24 14:44:41 +01:00
@@ -100,6 +100,7 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable {
private int receivedMovePackets;
private int processedMovePackets;
private AutoRecipe H = new AutoRecipe();
+ 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;
@@ -179,18 +180,25 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable {
2017-10-15 15:00:42 +02:00
}
this.minecraftServer.methodProfiler.a("keepAlive");
- long i = this.d();
-
- if (i - this.f >= 25000L) { // CraftBukkit
- if (this.g) {
- this.disconnect(new ChatMessage("disconnect.timeout", new Object[0]));
- } else {
- this.g = true;
- this.f = i;
- this.h = i;
- this.sendPacket(new PacketPlayOutKeepAlive(this.h));
+ // 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 = this.getCurrentMillis();
+ long elapsedTime = currentTime - this.getLastPing();
+ if (this.isPendingPing()) {
+ // We're pending a ping from the client
2017-12-24 14:44:41 +01:00
+ if (!this.processedDisconnect && elapsedTime >= KEEPALIVE_LIMIT) { // check keepalive limit, don't fire if already disconnected
2017-10-15 15:00:42 +02:00
+ PlayerConnection.LOGGER.warn("{} was kicked due to keepalive timeout!", this.player.getName()); // more info
+ this.disconnect(new ChatMessage("disconnect.timeout"));
+ }
+ } else {
+ if (elapsedTime >= 15000L) { // 15 seconds
+ this.setPendingPing(true);
+ this.setLastPing(currentTime);
+ this.setKeepAliveID(currentTime);
+ this.sendPacket(new PacketPlayOutKeepAlive(this.getKeepAliveID()));
}
}
+ // Paper end
this.minecraftServer.methodProfiler.b();
// CraftBukkit start
--
2018-01-16 04:13:17 +01:00
2.15.1
2017-10-15 15:00:42 +02:00