Browse Source

do not disconnect an already disconnected client

See https://github.com/miguelgrinberg/Flask-SocketIO/issues/312
pull/56/head
Miguel Grinberg 9 years ago
parent
commit
a58c184b0f
  1. 11
      socketio/server.py
  2. 17
      tests/test_server.py

11
socketio/server.py

@ -296,11 +296,12 @@ class Server(object):
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.

17
tests/test_server.py

@ -389,6 +389,23 @@ class TestServer(unittest.TestCase):
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 = {}

Loading…
Cancel
Save