Skip to content

Commit

Permalink
Catch IOErrors from uWSGI and explicitly close the driver (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
juneoh committed Dec 9, 2022
1 parent 0cbbd69 commit 678ae8b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/engineio/async_drivers/gevent_uwsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ def select_greenlet_runner(fd, event):

def close(self):
"""Disconnects uWSGI from the client."""
uwsgi.disconnect()
if self._req_ctx is None:
# better kill it here in case wait() is not called again
self._select_greenlet.kill()
self._event.set()
uwsgi.disconnect()

def _send(self, msg):
"""Transmits message either in binary or UTF-8 text mode,
Expand Down Expand Up @@ -115,6 +115,7 @@ def wait(self):
try:
msg = uwsgi.websocket_recv(request_context=self._req_ctx)
except IOError: # connection closed
self.close()
return None
return self._decode_received(msg)
else:
Expand All @@ -134,14 +135,18 @@ def wait(self):
except gevent.queue.Empty:
break
for msg in msgs:
self._send(msg)
try:
self._send(msg)
except IOError:
self.close()
return None
# maybe there is something to receive, if not, at least
# ensure uWSGI does its ping/ponging
while True:
try:
msg = uwsgi.websocket_recv_nb()
except IOError: # connection closed
self._select_greenlet.kill()
self.close()
return None
if msg: # message available
self.received_messages.append(
Expand Down

0 comments on commit 678ae8b

Please sign in to comment.