Fix race condition causing failed Travis builds #75.3 and #81.1.

This commit is contained in:
joo committed 2016-09-02 00:26:12 +01:00
1 parent bb1de5ca21
commit 38deda0d3b
1 file changed
+8 -4
+8 -4
View File
@@ -184,15 +184,16 @@ class Connection(object):
Attempt to begin connecting to the server. Attempt to begin connecting to the server.
May safely be called multiple times after the first, i.e. to reconnect. May safely be called multiple times after the first, i.e. to reconnect.
""" """
self.spawned = False
with self._write_lock: with self._write_lock:
# We hold the lock throughout, as connect() may be called by both
# the network thread and a parent thread simultaneously, during
# automatic version negotiation.
self.spawned = False
self._outgoing_packet_queue = deque() self._outgoing_packet_queue = deque()
self._connect() self._connect()
self._handshake() self._handshake()
self.reactor = LoginReactor(self)
self._start_network_thread()
login_start_packet = packets.LoginStartPacket() login_start_packet = packets.LoginStartPacket()
if self.auth_token: if self.auth_token:
login_start_packet.name = self.auth_token.profile.name login_start_packet.name = self.auth_token.profile.name
@@ -200,6 +201,9 @@ class Connection(object):
login_start_packet.name = self.username login_start_packet.name = self.username
self.write_packet(login_start_packet) self.write_packet(login_start_packet)
self.reactor = LoginReactor(self)
self._start_network_thread()
def _connect(self): def _connect(self):
# Connect a socket to the server and create a file object from the # Connect a socket to the server and create a file object from the
# socket. # socket.