conn: Optional[IrcConnection] = None
_cls_conn: type[IrcConnection] = IrcConnection
_expected_pong: str
- _retry_connect_in_s: int
+ _retry_connect_in_s: int = -1
_retry_connect_id: Optional[UUID] = None
def __init__(self, conn_setup: IrcConnSetup, channels: set[str], **kwargs
self.conn = self._cls_conn(
hostname=self.db.hostname, port=self.db.port,
_q_out=self._q_out, client_id=self.client_id)
- except IrcConnAbortException as e:
+ except IrcConnException as e:
self.db.connection_state = f'failed to connect: {e}'
+ if isinstance(e, IrcConnTimeoutException):
+ if not self._retry_connect_in_s > 0:
+ self._retry_connect_in_s = 1
+ self._client_trigger('_delayed_retry_connect')
except Exception as e: # pylint: disable=broad-exception-caught
self._put(ExceptionEvent(CrashingException(e)))
else:
# Do this in a thread, not to block flow of other (e.g. TUI) events.
Thread(target=connect, daemon=True, args=(self,)).start()
+ def _delayed_retry_connect(self) -> None:
+ def delayed_connect(self, wait_s: int, retry_connect_id: UUID
+ ) -> None:
+ sleep(wait_s)
+ if self._retry_connect_id == retry_connect_id:
+ self._client_trigger('connect')
+
+ self._retry_connect_id = uuid4()
+ self._alert(
+ f'will retry connecting in {self._retry_connect_in_s} seconds')
+ Thread(target=delayed_connect, daemon=True,
+ args=(self, self._retry_connect_in_s, self._retry_connect_id)
+ ).start()
+ self._retry_connect_in_s *= 2
+
def close(self) -> None:
'Close connection, wipe memory of its states, reconnect if indicated.'
if not self._autojoins:
self.conn.close()
self.conn = None
if self._retry_connect_in_s > 0:
- def delayed_connect(self, wait_s: int, retry_connect_id: UUID
- ) -> None:
- sleep(wait_s)
- if self._retry_connect_id == retry_connect_id:
- self._client_trigger('connect')
-
- self._retry_connect_id = uuid4()
- self._alert(
- f'will retry connecting in {self._retry_connect_in_s} seconds')
- Thread(target=delayed_connect, daemon=True,
- args=(self, self._retry_connect_in_s,
- self._retry_connect_id)
- ).start()
- self._retry_connect_in_s *= 2
+ self._delayed_retry_connect()
def on_handled_loop_exception(self, e: IrcConnException) -> None:
'On …AbortException, call .close(), on …Timeout… first (!) try PING.'