handle ServerboundKeepAlivePacket async

In 1.12.2, Mojang moved the processing of ServerboundKeepAlivePacket off the main
thread, while entirely correct for the server, this causes issues with
plugins which are expecting the PlayerQuitEvent on the main thread.

In order to counteract some bad behavior, we will post handling of the
disconnection to the main thread, but leave the actual processing of the packet
off the main thread.

also adding some additional logging in order to help work out what is causing
random disconnections for clients.
This commit is contained in:
Shane Freeder 2017-10-05 01:54:07 +01:00
parent 8c951e13df
commit 70e24c1b60

View file

@ -107,15 +107,27 @@
private void close() {
if (!this.closed) {
this.closedListenerTime = Util.getMillis();
@@ -80,6 +129,7 @@
@@ -80,13 +129,18 @@
@Override
public void handleKeepAlive(ServerboundKeepAlivePacket packet) {
+ PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); // CraftBukkit
+ //PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); // CraftBukkit // Paper - handle ServerboundKeepAlivePacket async
if (this.keepAlivePending && packet.getId() == this.keepAliveChallenge) {
int i = (int) (Util.getMillis() - this.keepAliveTime);
@@ -94,9 +144,57 @@
this.latency = (this.latency * 3 + i) / 4;
this.keepAlivePending = false;
} else if (!this.isSingleplayerOwner()) {
- this.disconnect(ServerCommonPacketListenerImpl.TIMEOUT_DISCONNECTION_MESSAGE);
+ // Paper start - This needs to be handled on the main thread for plugins
+ server.submit(() -> {
+ this.disconnect(ServerCommonPacketListenerImpl.TIMEOUT_DISCONNECTION_MESSAGE);
+ });
+ // Paper end - This needs to be handled on the main thread for plugins
}
}
@@ -94,9 +148,57 @@
@Override
public void handlePong(ServerboundPongPacket packet) {}
@ -174,7 +186,7 @@
@Override
public void handleResourcePackResponse(ServerboundResourcePackPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, (BlockableEventLoop) this.server);
@@ -104,11 +202,34 @@
@@ -104,11 +206,34 @@
ServerCommonPacketListenerImpl.LOGGER.info("Disconnecting {} due to resource pack {} rejection", this.playerProfile().getName(), packet.id());
this.disconnect((Component) Component.translatable("multiplayer.requiredTexturePrompt.disconnect"));
}
@ -209,7 +221,7 @@
this.disconnect(ServerCommonPacketListenerImpl.DISCONNECT_UNEXPECTED_QUERY);
}
@@ -116,7 +237,7 @@
@@ -116,7 +241,7 @@
Profiler.get().push("keepAlive");
long i = Util.getMillis();
@ -218,7 +230,7 @@
if (this.keepAlivePending) {
this.disconnect(ServerCommonPacketListenerImpl.TIMEOUT_DISCONNECTION_MESSAGE);
} else if (this.checkIfClosed(i)) {
@@ -156,6 +277,14 @@
@@ -156,6 +281,14 @@
}
public void send(Packet<?> packet, @Nullable PacketSendListener callbacks) {
@ -233,7 +245,7 @@
if (packet.isTerminal()) {
this.close();
}
@@ -175,20 +304,72 @@
@@ -175,20 +308,72 @@
}
}