diff --git a/socketio/server.py b/socketio/server.py index 0e0969b..04f46d6 100755 --- a/socketio/server.py +++ b/socketio/server.py @@ -290,12 +290,13 @@ class Server(object): def _handle_connect(self, sid, namespace): """Handle a client connection request.""" namespace = namespace or '/' + self.manager.connect(sid, namespace) if self._trigger_event('connect', namespace, sid, self.environ[sid]) is False: + self.manager.disconnect(sid, namespace) self._send_packet(sid, packet.Packet(packet.ERROR, namespace=namespace)) else: - self.manager.connect(sid, namespace) self._send_packet(sid, packet.Packet(packet.CONNECT, namespace=namespace)) diff --git a/tests/test_server.py b/tests/test_server.py index a21953b..968a07d 100755 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -167,7 +167,8 @@ class TestServer(unittest.TestCase): s.on('connect', handler) s._handle_eio_connect('123', 'environ') handler.assert_called_once_with('123', 'environ') - self.assertEqual(s.manager.connect.call_count, 0) + self.assertEqual(s.manager.connect.call_count, 1) + self.assertEqual(s.manager.disconnect.call_count, 1) s.eio.send.assert_called_once_with('123', '4', binary=False) def test_handle_connect_namespace_rejected(self, eio): @@ -177,7 +178,8 @@ class TestServer(unittest.TestCase): s.on('connect', handler, namespace='/foo') s._handle_eio_connect('123', 'environ') s._handle_eio_message('123', '0/foo') - self.assertEqual(s.manager.connect.call_count, 1) + self.assertEqual(s.manager.connect.call_count, 2) + self.assertEqual(s.manager.disconnect.call_count, 1) s.eio.send.assert_any_call('123', '4/foo', binary=False) def test_handle_disconnect(self, eio):