From cf2e4ea6c40973c25002e84374c194bb5e4c4973 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Mon, 17 May 2010 17:35:50 +0100 Subject: [PATCH] svc/conntrack: Make the kickpeers coroutine more robust. There are inevitable races between where conntrack enumerates the peers and when it submits the commands to modify the list. Also, there's no guarantee that `connect' -- which we use for initiating peer connections -- is running at all. So trap exceptions from the relevant commands and issue warnings as appropriate. --- svc/conntrack.8.in | 6 ++++++ svc/conntrack.in | 19 ++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/svc/conntrack.8.in b/svc/conntrack.8.in index 32217425..3e4fc725 100644 --- a/svc/conntrack.8.in +++ b/svc/conntrack.8.in @@ -269,6 +269,12 @@ The configuration file is invalid. The token names a Python exception; the .I error-text describes the problem encountered, though it may not be very useful. +.SP +.BI "USER conntrack connect-failed " peer " " tokens\fR... +An attempt to connect the named +.I peer +failed; the error message is given by the +.IR tokens . . .\"-------------------------------------------------------------------------- .SH "SUMMARY" diff --git a/svc/conntrack.in b/svc/conntrack.in index b80f92ed..827598fe 100644 --- a/svc/conntrack.in +++ b/svc/conntrack.in @@ -265,12 +265,25 @@ def kickpeers(): if what == 'up': found = True elif what == 'down': - changes.append(lambda p=p: SM.kill(p)) + def _(p = p): + try: + SM.kill(p) + except T.TripeError, exc: + if exc.args[0] == 'unknown-peer': + ## Inherently racy; don't worry about this. + pass + else: + raise + changes.append(_) ## Start the right one if necessary. if want is not None and (not found or ip != lastip.get(g, None)): - changes.append(lambda: T._simple(SM.svcsubmit('connect', 'active', - want))) + def _(want = want): + try: + SM.svcsubmit('connect', 'active', want) + except T.TripeError, exc: + SM.warn('conntrack', 'connect-failed', want, *exc.args) + changes.append(_) lastip[g] = ip ## Commit the changes. -- 2.11.0