From ae0def412a3469a5e4b432360526a193c06be40a Mon Sep 17 00:00:00 2001 From: "Alexander van Gessel (AI0867)" Date: Mon, 8 Oct 2012 12:29:49 +0200 Subject: [PATCH] Expire disconnected connections if they aren't needed or can't reconnect --- irkerd | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/irkerd b/irkerd index 302b48a..6d6c15e 100755 --- a/irkerd +++ b/irkerd @@ -187,7 +187,11 @@ class Connection: now = time.time() xmit_timeout = now > self.last_xmit + XMIT_TTL ping_timeout = now > self.last_ping + PING_TTL - if (xmit_timeout or ping_timeout) and self.status != "disconnected": + if self.status == "disconnected": + # If the queue is empty, we can drop this connection. + self.status = "expired" + break + elif xmit_timeout or ping_timeout: self.irker.debug(1, "timing out connection to %s at %s (ping_timeout=%s, xmit_timeout=%s)" % (self.servername, time.asctime(), ping_timeout, xmit_timeout)) with self.irker.library_lock: self.connection.context = None @@ -201,6 +205,13 @@ class Connection: # reflex arc it is highly unlikely any human will ever # notice. time.sleep(ANTI_BUZZ_DELAY) + elif self.status == "disconnected" \ + and time.time() > self.last_xmit + DISCONNECT_TTL: + # Queue is nonempty, but the IRC server might be + # down. Letting failed connections retain queue + # space forever would be a memory leak. + self.status = "expired" + break elif not self.connection: # Queue is nonempty but server isn't connected. with self.irker.library_lock: @@ -230,13 +241,6 @@ class Connection: # Don't buzz on the empty-queue test while we're # handshaking time.sleep(ANTI_BUZZ_DELAY) - elif self.status == "disconnected" \ - and time.time() > self.last_xmit + DISCONNECT_TTL: - # Queue is nonempty, but the IRC server might be - # down. Letting failed connections retain queue - # space forever would be a memory leak. - self.status = "expired" - break elif self.status == "unseen" \ and time.time() > self.last_xmit + UNSEEN_TTL: # Nasty people could attempt a denial-of-service -- 2.26.2