From 9c9378ae582e7af88e390be36991a51f44f00e35 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Thu, 28 Apr 2022 15:16:46 +0100 Subject: [PATCH] svc/connect.in: Maintain time of last reconnect attempt and add rate limit. This isn't used yet, but it's there as a general mechanism. Don't rate-limit reconnections provoked by the pinger internally because (a) these are relatively infrequent anyway by the nature of the pinger mechanism, and (b) the current rate-limiting strategy is simply to ignore a reconnection request if we've already made an attempt fairly recently, so there isn't (and it's not worth building) the necessary machinery to defer reconnection, and determine whether a deferred reconnection is still needed. --- svc/connect.in | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/svc/connect.in b/svc/connect.in index e679ff59..fa5a22c2 100644 --- a/svc/connect.in +++ b/svc/connect.in @@ -413,6 +413,7 @@ class PingPeer (object): me._ping() else: me._timer = M.SelTimer(now + me._every, me._time) + me._last_reconn = now def update(me, peer): """ @@ -451,11 +452,22 @@ class PingPeer (object): if me._connectp: T.spawn(run_connect, peer, peer.get('connect')) me._timer = M.SelTimer(now + me._every, me._time) me._sabotage = False + me._last_reconn = now else: S.kill(me._peer) except T.TripeError, e: if e.args[0] == 'unknown-peer': me._pinger.kill(me._peer) + def reconnect(me): + """ + Attempt reconnection to the peer. + + Applies rate-limiting so that we don't hammer a remote peer just because + we notice several problems in a short time interval. + """ + now = time() + if now >= me._last_reconn + 5: me._reconnect(now) + def event(me, code, stuff): """ Respond to an event which happened to this peer. -- 2.11.0