From: Matt Hazinski Date: Tue, 30 Dec 2014 01:21:24 +0000 (-0500) Subject: Move UDP listen inside try block X-Git-Tag: allmydata-tahoe-1.10.1a1~94^2 X-Git-Url: https://git.rkrishnan.org/listings/install-details.html?a=commitdiff_plain;h=4a18f03960dac88717d01b59b919a28bbd48ffea;p=tahoe-lafs%2Ftahoe-lafs.git Move UDP listen inside try block --- diff --git a/src/allmydata/util/iputil.py b/src/allmydata/util/iputil.py index 4ea6aa6f..af44d186 100644 --- a/src/allmydata/util/iputil.py +++ b/src/allmydata/util/iputil.py @@ -6,6 +6,7 @@ from sys import platform # from Twisted from twisted.internet import defer, threads, reactor from twisted.internet.protocol import DatagramProtocol +from twisted.internet.error import CannotListenError from twisted.python.procutils import which from twisted.python import log @@ -125,16 +126,17 @@ def get_local_ip_for(target): # avoid this DNS lookup. This also makes node startup fractionally # faster. return None - udpprot = DatagramProtocol() - port = reactor.listenUDP(0, udpprot) + try: + udpprot = DatagramProtocol() + port = reactor.listenUDP(0, udpprot) udpprot.transport.connect(target_ipaddr, 7) localip = udpprot.transport.getHost().host - except socket.error: + d = port.stopListening() + d.addErrback(log.err) + except (socket.error, CannotListenError): # no route to that host localip = None - d = port.stopListening() - d.addErrback(log.err) return localip