Skip to content

Commit 690acf4

Browse files
committed
Handle a race condition on protocol connection loss
If the connection was lost before a connection object was created it would lead to an error attempting to remove the connection from the global pool.
1 parent bcd7517 commit 690acf4

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

receptor/protocol.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class BaseProtocol(asyncio.Protocol):
3434
def __init__(self, receptor, loop):
3535
self.receptor = receptor
3636
self.loop = loop
37+
self.connection = None
3738

3839
async def watch_queue(self, node, transport):
3940
'''
@@ -69,7 +70,8 @@ def connection_made(self, transport):
6970
self.loop.create_task(self.wait_greeting())
7071

7172
def connection_lost(self, exc):
72-
self.receptor.remove_connection(self.connection)
73+
if self.connection is not None:
74+
self.receptor.remove_connection(self.connection)
7375

7476
def data_received(self, data):
7577
logger.debug(data)

0 commit comments

Comments
 (0)