Browse Source

fixed memory leak on rejected connections for asyncio

pull/146/head
Miguel Grinberg 8 years ago
parent
commit
9350775634
No known key found for this signature in database GPG Key ID: 36848B262DF5F06C
  1. 2
      socketio/asyncio_server.py
  2. 2
      tests/test_asyncio_server.py

2
socketio/asyncio_server.py

@ -258,6 +258,8 @@ class AsyncServer(server.Server):
self.manager.disconnect(sid, namespace) self.manager.disconnect(sid, namespace)
await self._send_packet(sid, packet.Packet(packet.ERROR, await self._send_packet(sid, packet.Packet(packet.ERROR,
namespace=namespace)) namespace=namespace))
if sid in self.environ: # pragma: no cover
del self.environ[sid]
return False return False
else: else:
await self._send_packet(sid, packet.Packet(packet.CONNECT, await self._send_packet(sid, packet.Packet(packet.CONNECT,

2
tests/test_asyncio_server.py

@ -267,6 +267,7 @@ class TestAsyncServer(unittest.TestCase):
handler.assert_called_once_with('123', 'environ') handler.assert_called_once_with('123', 'environ')
self.assertEqual(s.manager.connect.call_count, 1) self.assertEqual(s.manager.connect.call_count, 1)
self.assertEqual(s.manager.disconnect.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) s.eio.send.mock.assert_called_once_with('123', '4', binary=False)
def test_handle_connect_namespace_rejected(self, eio): def test_handle_connect_namespace_rejected(self, eio):
@ -279,6 +280,7 @@ class TestAsyncServer(unittest.TestCase):
_run(s._handle_eio_message('123', '0/foo')) _run(s._handle_eio_message('123', '0/foo'))
self.assertEqual(s.manager.connect.call_count, 2) self.assertEqual(s.manager.connect.call_count, 2)
self.assertEqual(s.manager.disconnect.call_count, 1) self.assertEqual(s.manager.disconnect.call_count, 1)
self.assertEqual(s.environ, {})
s.eio.send.mock.assert_any_call('123', '4/foo', binary=False) s.eio.send.mock.assert_any_call('123', '4/foo', binary=False)
def test_handle_disconnect(self, eio): def test_handle_disconnect(self, eio):

Loading…
Cancel
Save