From 6aa6236031bcaea4c20a13cc145d3cae499fd775 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Tue, 21 Mar 2023 00:13:26 +0200 Subject: [PATCH 1/2] =?UTF-8?q?Fix=20typo=20"Mo=20data"=20=E2=86=92=20"No?= =?UTF-8?q?=20data"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ircbot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ircbot.py b/ircbot.py index 7ec5f50..1a0e66d 100644 --- a/ircbot.py +++ b/ircbot.py @@ -240,7 +240,7 @@ class ServerThread(threading.Thread): if event | select.POLLIN: data = self.server_socket.recv(1024) - # Mo data to be read even as POLLIN triggered → connection has broken + # No data to be read even as POLLIN triggered → connection has broken # Log it and try reconnecting if data == b'': self.logging_channel.send((logmessage_types.internal, internal_submessage_types.error, 'Empty read')) From c23f48c329c93eef10fc2cdba30eee2df01161b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Fri, 16 Jun 2023 11:31:49 +0300 Subject: [PATCH 2/2] Handle connection being reset while reading --- ircbot.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ircbot.py b/ircbot.py index 1a0e66d..8dc3a49 100644 --- a/ircbot.py +++ b/ircbot.py @@ -238,7 +238,12 @@ class ServerThread(threading.Thread): if fd == self.server_socket.fileno(): # Ready to receive, read into buffer and handle full messages if event | select.POLLIN: - data = self.server_socket.recv(1024) + try: + data = self.server_socket.recv(1024) + except ConnectionResetError: + self.logging_channel.send((logmessage_types.internal, internal_submessage_types.error, 'Connection reset while reading')) + reconnecting = True + break # No data to be read even as POLLIN triggered → connection has broken # Log it and try reconnecting