Fix the connection-aging logic.
authorEric S. Raymond <esr@thyrsus.com>
Wed, 3 Oct 2012 19:08:49 +0000 (15:08 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Wed, 3 Oct 2012 19:08:49 +0000 (15:08 -0400)
NEWS
irkerd

diff --git a/NEWS b/NEWS
index 40100826ceaafeead9ce76b446bc329ea5906343..ba4881c2c30edd8b5c033109b0839a6c25bb6795 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@
 1.6 @
   In 1.5 trying to appease pylint broke the Mercurial hook.
   Added credits for contributors in hacking.txt.
+  Fix the aging out of connections when we hit a resource limit.
 
 1.5 @ 2012-10-03
   Mercurial support.
diff --git a/irkerd b/irkerd
index 651bad04d320285b3fbebd8f9a40d5b021aa8cf2..5785ce5dcebd266f91e41f7aeaee39a1aef819e7 100755 (executable)
--- a/irkerd
+++ b/irkerd
@@ -298,6 +298,9 @@ class Dispatcher:
         "Does this server-port combination have any live connections?"
         self.connections = [x for x in self.connections if x.live()]
         return len(self.connections) > 0
+    def last_xmit(self):
+        "Return the time of the most recent transmission."
+        return max([x.last_xmit for x in self.connections])
 
 class Irker:
     "Persistent IRC multiplexer."
@@ -419,10 +422,12 @@ class Irker:
                             # assumption that message activity is likely
                             # to be clumpy.
                             oldest = None
+                            oldtime = float("inf")
                             if len(self.servers) >= CONNECTION_MAX:
                                 for (name, server) in self.servers.items():
-                                    if not oldest or server.last_xmit < self.servers[oldest].last_xmit:
+                                    if server.last_xmit() < oldtime:
                                         oldest = name
+                                        oldtime = server.last_xmit()
                                 del self.servers[oldest]
         except ValueError:
             self.logerr("can't recognize JSON on input: %s" % repr(line))