2016-03-01 01:23:45 +01:00
|
|
|
From 6a6f6dd1e01b57ef61f4c90abc1d2c2ecfae00db Mon Sep 17 00:00:00 2001
|
2014-07-21 22:46:54 +02:00
|
|
|
From: Jonas Konrad <me@yawk.at>
|
|
|
|
Date: Fri, 25 Apr 2014 23:46:46 +0200
|
|
|
|
Subject: [PATCH] Fix race condition that could kill connections before they
|
|
|
|
were initiated
|
|
|
|
|
|
|
|
Because NetworkManagers are registered before they get their channel in
|
|
|
|
channelActive, the ServerConnection would remove them sometimes because
|
|
|
|
it thought they were disconnected. This commit fixes this by introducing
|
|
|
|
a 'preparing' variable that is true while the NetworkManager is not
|
|
|
|
initialized. The ServerConnection does not remove NetworkManagers with
|
|
|
|
this flag.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/NetworkManager.java b/src/main/java/net/minecraft/server/NetworkManager.java
|
2016-02-29 22:33:06 +01:00
|
|
|
index c6f9955..4c6dfb1 100644
|
2014-07-21 22:46:54 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/NetworkManager.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/NetworkManager.java
|
2016-02-29 22:33:06 +01:00
|
|
|
@@ -68,6 +68,7 @@ public class NetworkManager extends SimpleChannelInboundHandler<Packet<?>> {
|
2015-02-28 12:36:22 +01:00
|
|
|
public SocketAddress l;
|
2014-07-21 22:46:54 +02:00
|
|
|
public java.util.UUID spoofedUUID;
|
2014-11-28 02:17:45 +01:00
|
|
|
public com.mojang.authlib.properties.Property[] spoofedProfile;
|
2014-07-21 22:46:54 +02:00
|
|
|
+ public boolean preparing = true;
|
|
|
|
// Spigot End
|
2015-02-28 12:36:22 +01:00
|
|
|
private PacketListener m;
|
|
|
|
private IChatBaseComponent n;
|
2016-02-29 22:33:06 +01:00
|
|
|
@@ -82,6 +83,9 @@ public class NetworkManager extends SimpleChannelInboundHandler<Packet<?>> {
|
2014-07-21 22:46:54 +02:00
|
|
|
super.channelActive(channelhandlercontext);
|
2015-05-09 22:23:26 +02:00
|
|
|
this.channel = channelhandlercontext.channel();
|
|
|
|
this.l = this.channel.remoteAddress();
|
2014-07-21 22:46:54 +02:00
|
|
|
+ // Spigot Start
|
|
|
|
+ this.preparing = false;
|
|
|
|
+ // Spigot End
|
|
|
|
|
2014-11-28 02:17:45 +01:00
|
|
|
try {
|
2016-02-29 22:33:06 +01:00
|
|
|
this.setProtocol(EnumProtocol.HANDSHAKING);
|
|
|
|
@@ -236,6 +240,9 @@ public class NetworkManager extends SimpleChannelInboundHandler<Packet<?>> {
|
2014-07-21 22:46:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void close(IChatBaseComponent ichatbasecomponent) {
|
|
|
|
+ // Spigot Start
|
|
|
|
+ this.preparing = false;
|
|
|
|
+ // Spigot End
|
2015-05-09 22:23:26 +02:00
|
|
|
if (this.channel.isOpen()) {
|
|
|
|
this.channel.close(); // We can't wait as this may be called from an event loop.
|
2015-02-28 12:36:22 +01:00
|
|
|
this.n = ichatbasecomponent;
|
2014-07-21 22:46:54 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/ServerConnection.java b/src/main/java/net/minecraft/server/ServerConnection.java
|
2016-02-29 22:33:06 +01:00
|
|
|
index 827bfaf..7797575 100644
|
2014-07-21 22:46:54 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/ServerConnection.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/ServerConnection.java
|
2016-02-29 22:33:06 +01:00
|
|
|
@@ -167,6 +167,10 @@ public class ServerConnection {
|
|
|
|
networkmanager.stopReading();
|
|
|
|
}
|
|
|
|
} else {
|
2014-11-28 02:17:45 +01:00
|
|
|
+ // Spigot Start
|
|
|
|
+ // Fix a race condition where a NetworkManager could be unregistered just before connection.
|
|
|
|
+ if (networkmanager.preparing) continue;
|
|
|
|
+ // Spigot End
|
|
|
|
iterator.remove();
|
2016-02-29 22:33:06 +01:00
|
|
|
networkmanager.handleDisconnection();
|
|
|
|
}
|
2014-07-21 22:46:54 +02:00
|
|
|
--
|
2016-02-29 22:33:06 +01:00
|
|
|
2.5.0
|
2014-07-21 22:46:54 +02:00
|
|
|
|