home · contact · privacy
For interpreting ERROR messages towards connection retries, use regex matching, add...
authorChristian Heller <c.heller@plomlompom.de>
Mon, 3 Nov 2025 05:02:32 +0000 (06:02 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Mon, 3 Nov 2025 05:02:32 +0000 (06:02 +0100)
src/ircplom/client.py

index 67945837f841706c08a9eb0d2de3edf515727c19..d9ce45c0f1591a8131249c24e5a7a1071de76aac 100644 (file)
@@ -4,6 +4,7 @@ from abc import ABC, abstractmethod
 from base64 import b64encode
 from dataclasses import dataclass, InitVar
 from getpass import getuser
+from re import search as re_search, IGNORECASE as re_IGNORECASE
 from threading import Thread
 from time import sleep
 from typing import (Any, Callable, Collection, Generic, Iterable, Iterator,
@@ -19,6 +20,10 @@ from ircplom.msg_parse_expectations import MSG_EXPECTATIONS
 
 
 _NAMES_DESIRED_SERVER_CAPS = ('sasl',)
+_DISCONNECT_MSG_REGEXES_TO_RETRY_ON = (
+    r'^Closing Link: \(Connection timed out\)$',
+    r'^Closing Link: \(Ping timeout: [0-9]+ seconds\)$'
+)
 
 
 class SendFail(Exception):
@@ -891,9 +896,12 @@ class Client(ABC, ClientQueueMixin):
 
     def consider_retry(self) -> None:
         'Interpret .db.connection_state, on triggers set retry connect.'
-        if self.db.connection_state.endswith('timed out)')\
-                and not self._retry_connect_in_s > 0:
-            self._retry_connect_in_s = 1
+        if not self._retry_connect_in_s > 0:
+            for _ in [
+                    re for re in _DISCONNECT_MSG_REGEXES_TO_RETRY_ON
+                    if re_search(re, self.db.connection_state, re_IGNORECASE)]:
+                self._retry_connect_in_s = 1
+                break
 
     def close(self) -> None:
         'Close connection, wipe memory of its states, reconnect if indicated.'