Skip to content

Commit

Permalink
do not disconnect an already disconnected client
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Sep 4, 2016
1 parent 0107123 commit a58c184
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
11 changes: 6 additions & 5 deletions socketio/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,12 @@ def disconnect(self, sid, namespace=None):
argument is omitted the default namespace is used.
"""
namespace = namespace or '/'
self.logger.info('Disconnecting %s [%s]', sid, namespace)
self._send_packet(sid, packet.Packet(packet.DISCONNECT,
namespace=namespace))
self._trigger_event('disconnect', namespace, sid)
self.manager.disconnect(sid, namespace=namespace)
if self.manager.is_connected(sid, namespace=namespace):
self.logger.info('Disconnecting %s [%s]', sid, namespace)
self._send_packet(sid, packet.Packet(packet.DISCONNECT,
namespace=namespace))
self._trigger_event('disconnect', namespace, sid)
self.manager.disconnect(sid, namespace=namespace)

def transport(self, sid):
"""Return the name of the transport used by the client.
Expand Down
17 changes: 17 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,23 @@ def test_disconnect_namespace(self, eio):
s.disconnect('123', namespace='/foo')
s.eio.send.assert_any_call('123', '1/foo', binary=False)

def test_disconnect_twice(self, eio):
s = server.Server()
s._handle_eio_connect('123', 'environ')
s.disconnect('123')
calls = s.eio.send.call_count
s.disconnect('123')
self.assertEqual(calls, s.eio.send.call_count)

def test_disconnect_twice_namespace(self, eio):
s = server.Server()
s._handle_eio_connect('123', 'environ')
s._handle_eio_message('123', '0/foo')
s.disconnect('123', namespace='/foo')
calls = s.eio.send.call_count
s.disconnect('123', namespace='/foo')
self.assertEqual(calls, s.eio.send.call_count)

def test_namespace_handler(self, eio):
result = {}

Expand Down

0 comments on commit a58c184

Please sign in to comment.