Skip to content

Commit 9bd9c40

Browse files
committed
Check for ConnectionResetError when reading bytes from client
1 parent c61ca53 commit 9bd9c40

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

websocket_server/websocket_server.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ def read_bytes(self, num):
190190
def read_next_message(self):
191191
try:
192192
b1, b2 = self.read_bytes(2)
193+
except ConnectionResetError:
194+
logger.info("Client closed connection.")
195+
self.keep_alive = 0
196+
return
193197
except ValueError as e:
194198
b1, b2 = 0, 0
195199

@@ -198,10 +202,6 @@ def read_next_message(self):
198202
masked = b2 & MASKED
199203
payload_length = b2 & PAYLOAD_LEN
200204

201-
if not b1:
202-
logger.info("Client closed connection.")
203-
self.keep_alive = 0
204-
return
205205
if opcode == OPCODE_CLOSE_CONN:
206206
logger.info("Client asked to close connection.")
207207
self.keep_alive = 0

0 commit comments

Comments
 (0)