Skip to content

Commit

Permalink
fixed memory leak on rejected connections for asyncio
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Nov 13, 2017
1 parent 63b6908 commit 9350775
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions socketio/asyncio_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ async def _handle_connect(self, sid, namespace):
self.manager.disconnect(sid, namespace)
await self._send_packet(sid, packet.Packet(packet.ERROR,
namespace=namespace))
if sid in self.environ: # pragma: no cover
del self.environ[sid]
return False
else:
await self._send_packet(sid, packet.Packet(packet.CONNECT,
Expand Down
2 changes: 2 additions & 0 deletions tests/test_asyncio_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ def test_handle_connect_rejected(self, eio):
handler.assert_called_once_with('123', 'environ')
self.assertEqual(s.manager.connect.call_count, 1)
self.assertEqual(s.manager.disconnect.call_count, 1)
self.assertEqual(s.environ, {})
s.eio.send.mock.assert_called_once_with('123', '4', binary=False)

def test_handle_connect_namespace_rejected(self, eio):
Expand All @@ -279,6 +280,7 @@ def test_handle_connect_namespace_rejected(self, eio):
_run(s._handle_eio_message('123', '0/foo'))
self.assertEqual(s.manager.connect.call_count, 2)
self.assertEqual(s.manager.disconnect.call_count, 1)
self.assertEqual(s.environ, {})
s.eio.send.mock.assert_any_call('123', '4/foo', binary=False)

def test_handle_disconnect(self, eio):
Expand Down

0 comments on commit 9350775

Please sign in to comment.