Archiviert
13
0
Dieses Repository wurde am 2024-12-25 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
Paper-Old/patches/unapplied/server/0165-revert-serverside-behavior-of-keepalives.patch

71 Zeilen
4.2 KiB
Diff

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.
2023-09-21 23:04:51 +02:00
diff --git a/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
index 156cb6a00a2580eb16e05c80bc3267128b5804a3..d0f89a66734423ceea67fbeb99b0e72797f80e63 100644
2023-09-21 23:04:51 +02:00
--- a/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
2023-12-25 11:51:44 +01:00
@@ -48,12 +48,13 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
2023-09-21 23:04:51 +02:00
private static final Component TIMEOUT_DISCONNECTION_MESSAGE = Component.translatable("disconnect.timeout");
protected final MinecraftServer server;
public final Connection connection; // Paper
2022-06-07 22:45:38 +02:00
- private long keepAliveTime;
2023-09-21 23:04:51 +02:00
+ private long keepAliveTime = Util.getMillis(); // Paper
2022-06-07 22:45:38 +02:00
private boolean keepAlivePending;
private long keepAliveChallenge;
2023-09-21 23:04:51 +02:00
private int latency;
private volatile boolean suspendFlushingOnServerThread = false;
2023-12-25 11:51:44 +01:00
public final java.util.Map<java.util.UUID, net.kyori.adventure.resource.ResourcePackCallback> packCallbacks = new java.util.concurrent.ConcurrentHashMap<>(); // Paper - adventure resource pack callbacks
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
2023-09-21 23:04:51 +02:00
public ServerCommonPacketListenerImpl(MinecraftServer minecraftserver, Connection networkmanager, CommonListenerCookie commonlistenercookie, ServerPlayer player) { // CraftBukkit
this.server = minecraftserver;
2023-12-25 11:51:44 +01:00
@@ -183,18 +184,25 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
2021-06-11 14:02:28 +02:00
2023-09-21 23:04:51 +02:00
protected void keepConnectionAlive() {
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) {
+ // Paper start - give clients a longer time to respond to pings as per pre 1.12.2 timings
2023-06-07 21:37:42 +02:00
+ // 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
2023-09-21 23:04:51 +02:00
this.disconnect(ServerCommonPacketListenerImpl.TIMEOUT_DISCONNECTION_MESSAGE);
- } else {
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 - give clients a longer time to respond to pings as per pre 1.12.2 timings
2021-06-11 14:02:28 +02:00
this.server.getProfiler().pop();
2023-09-21 23:04:51 +02:00
}