From: Eric S. Raymond Date: Wed, 3 Oct 2012 19:08:49 +0000 (-0400) Subject: Fix the connection-aging logic. X-Git-Tag: 1.6~11 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=22e794417340336efd321d5f079937c8b2dd91db;p=irker.git Fix the connection-aging logic. --- diff --git a/NEWS b/NEWS index 4010082..ba4881c 100644 --- 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 651bad0..5785ce5 100755 --- 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))