Skip to content

Commit

Permalink
Improve handling of immediately closed sockets with Ping/Pong enabled (
Browse files Browse the repository at this point in the history
  • Loading branch information
lkedziora authored Jan 10, 2024
1 parent 5a5dbec commit 632ec52
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/simple_websocket/ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ def _thread(self):
if self.ping_interval:
next_ping = time() + self.ping_interval
sel = self.selector_class()
sel.register(self.sock, selectors.EVENT_READ, True)
try:
sel.register(self.sock, selectors.EVENT_READ, True)
except ValueError: # pragma: no cover
self.connected = False

while self.connected:
try:
Expand All @@ -154,7 +157,8 @@ def _thread(self):
raise OSError()
self.ws.receive_data(in_data)
self.connected = self._handle_events()
except (OSError, ConnectionResetError): # pragma: no cover
except (OSError, ConnectionResetError,
LocalProtocolError): # pragma: no cover
self.connected = False
self.event.set()
break
Expand Down

0 comments on commit 632ec52

Please sign in to comment.