From 935077563490f890f1b1d596be9fc38c8d65588b Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Sun, 12 Nov 2017 18:36:00 -0800 Subject: [PATCH] fixed memory leak on rejected connections for asyncio --- socketio/asyncio_server.py | 2 ++ tests/test_asyncio_server.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/socketio/asyncio_server.py b/socketio/asyncio_server.py index 38aade1..2188f22 100644 --- a/socketio/asyncio_server.py +++ b/socketio/asyncio_server.py @@ -258,6 +258,8 @@ class AsyncServer(server.Server): 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, diff --git a/tests/test_asyncio_server.py b/tests/test_asyncio_server.py index 3be1ac0..c4272c3 100644 --- a/tests/test_asyncio_server.py +++ b/tests/test_asyncio_server.py @@ -267,6 +267,7 @@ class TestAsyncServer(unittest.TestCase): 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): @@ -279,6 +280,7 @@ class TestAsyncServer(unittest.TestCase): _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):