Skip to content

Commit

Permalink
detect lost connections (asyncio)
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed May 6, 2017
1 parent e9a3161 commit 9a96896
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
1 change: 1 addition & 0 deletions engineio/async_eventlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

class WebSocketWSGI(_WebSocketWSGI):
def __init__(self, *args, **kwargs):
super(WebSocketWSGI, self).__init__(*args, **kwargs)
self._sock = None

def __call__(self, environ, start_response):
Expand Down
2 changes: 1 addition & 1 deletion engineio/asyncio_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ async def writer():
while True:
p = None
try:
p = await ws.wait()
p = await asyncio.wait_for(ws.wait(), self.server.ping_timeout)
except:
break
if p is None:
Expand Down
9 changes: 2 additions & 7 deletions engineio/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,11 @@ def writer():
break
if not packets:
# empty packet list returned -> connection closed
if not self.closed: # pragma: no cover
self.close(wait=True, abort=True)
break
try:
for pkt in packets:
ws.send(pkt.encode(always_bytes=False))
except:
if not self.closed: # pragma: no cover
self.close(wait=True, abort=True)
break
writer_task = self.server.start_background_task(writer)

Expand All @@ -203,7 +199,7 @@ def writer():
except Exception as e:
# if the socket is already closed, we can assume this is a
# downstream error of that
if not self.closed:
if not self.closed: # pragma: no cover
self.server.logger.info(
'%s: Unexpected error "%s", closing connection',
self.sid, str(e))
Expand All @@ -227,8 +223,7 @@ def writer():

self.queue.put(None) # unlock the writer task so that it can exit
writer_task.join()
if not self.closed:
self.close(wait=True, abort=True)
self.close(wait=True, abort=True)
if reraise_exc:
raise reraise_exc

Expand Down

0 comments on commit 9a96896

Please sign in to comment.