Skip to content

Commit

Permalink
Handle ConnectionClosed in the reader task (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
mehaase committed Jan 24, 2019
1 parent 2384e70 commit 069da59
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion trio_websocket/_impl.py
Expand Up @@ -613,6 +613,9 @@ async def aclose(self, code=1000, reason=None):
await self._recv_channel.aclose()
await self._write_pending()
await self._close_handshake.wait()
except ConnectionClosed:
# If _write_pending() raised ConnectionClosed, then we can bail out.
pass
finally:
# If cancelled during WebSocket close, make sure that the underlying
# stream is closed.
Expand Down Expand Up @@ -908,7 +911,10 @@ async def _reader_task(self):

if self.is_client:
# Clients need to initiate the negotiation:
await self._write_pending()
try:
await self._write_pending()
except ConnectionClosed:
self._reader_running = False

while self._reader_running:
# Process events.
Expand All @@ -922,6 +928,9 @@ async def _reader_task(self):
except KeyError:
logger.warning('%s received unknown event type: "%s"', self,
event_type)
except ConnectionClosed:
self._reader_running = False
break

# Get network data.
try:
Expand Down

0 comments on commit 069da59

Please sign in to comment.