From 66e17fb387510522bc9a1718ae9da8b0f6ace005 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Sun, 12 Nov 2017 16:41:14 -0800 Subject: [PATCH] fixed memory leak on rejected connections Fixes https://github.com/miguelgrinberg/Flask-SocketIO/issues/574 --- socketio/server.py | 2 ++ tests/test_server.py | 1 + tox.ini | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/socketio/server.py b/socketio/server.py index 3295bd7..f9f9269 100644 --- a/socketio/server.py +++ b/socketio/server.py @@ -422,6 +422,8 @@ class Server(object): self.manager.disconnect(sid, namespace) 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: self._send_packet(sid, packet.Packet(packet.CONNECT, diff --git a/tests/test_server.py b/tests/test_server.py index b646a27..03370d3 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -204,6 +204,7 @@ class TestServer(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.assert_called_once_with('123', '4', binary=False) def test_handle_connect_namespace_rejected(self, eio): diff --git a/tox.ini b/tox.ini index 1472061..c326cd0 100644 --- a/tox.ini +++ b/tox.ini @@ -22,7 +22,7 @@ basepython=python3.6 deps= flake8 commands= - flake8 --exclude=".*" --ignore=E402 socketio tests + flake8 --exclude=".*" --ignore=E402,E722 socketio tests [testenv:docs] basepython=python2.7