diff --git a/socketio/base_manager.py b/socketio/base_manager.py index 283db13..09bef7c 100644 --- a/socketio/base_manager.py +++ b/socketio/base_manager.py @@ -64,6 +64,8 @@ class BaseManager(object): def disconnect(self, sid, namespace): """Register a client disconnect from a namespace.""" + if namespace not in self.rooms: + return rooms = [] for room_name, room in six.iteritems(self.rooms[namespace]): if sid in room: diff --git a/tests/test_base_manager.py b/tests/test_base_manager.py index 55141d4..d4291f9 100644 --- a/tests/test_base_manager.py +++ b/tests/test_base_manager.py @@ -99,6 +99,11 @@ class TestBaseManager(unittest.TestCase): self.bm.disconnect('123', '/') self.assertNotIn('123', self.bm.callbacks) + def test_disconnect_bad_namespace(self): + self.bm.connect('123', '/') + self.bm.connect('123', '/foo') + self.bm.disconnect('123', '/bar') # should not assert + def test_trigger_callback(self): self.bm.connect('123', '/') self.bm.connect('123', '/foo')