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.

By: Jonas Konrad <me@yawk.at>
This commit is contained in:
CraftBukkit/Spigot
2014-04-25 23:46:46 +02:00
parent 8b9d2faa11
commit 05f3042755
2 changed files with 36 additions and 6 deletions

View File

@@ -43,3 +43,14 @@
Iterator<Connection> iterator = this.connections.iterator();
while (iterator.hasNext()) {
@@ -176,6 +193,10 @@
networkmanager.setReadOnly();
}
} else {
+ // Spigot Start
+ // Fix a race condition where a NetworkManager could be unregistered just before connection.
+ if (networkmanager.preparing) continue;
+ // Spigot End
iterator.remove();
networkmanager.handleDisconnection();
}