Skip to content

Commit

Permalink
do not crash if recipient of a message is gone
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed May 13, 2016
1 parent 12532c0 commit 95c9a55
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions engineio/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,13 @@ def send(self, sid, data, binary=None):
(Python 3) are sent as text, and str (Python 2) and
bytes (Python 3) are sent as binary.
"""
self._get_socket(sid).send(packet.Packet(packet.MESSAGE, data=data,
binary=binary))
try:
socket = self._get_socket(sid)
except KeyError:
# the socket is not available
self.logger.warning('Cannot send to sid %s', sid)
return
socket.send(packet.Packet(packet.MESSAGE, data=data, binary=binary))

def disconnect(self, sid=None):
"""Disconnect a client.
Expand Down

0 comments on commit 95c9a55

Please sign in to comment.