Skip to content

Catch IOErrors from uWSGI and explicitly close the driver #301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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