mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-31 16:36:20 +00:00
iputil.py: avoid DirtyReactorError when running tests offline
The udpprot.transport.connect() fails if we don't have a network connection, but the port is still listening, so trial gives us a DirtyReactorError. The fix is a "finally:" which does port.stopListening() even in this case. Closes ticket:2769
This commit is contained in:
parent
431d762872
commit
ce548687f8
@ -130,10 +130,16 @@ def get_local_ip_for(target):
|
||||
try:
|
||||
udpprot = DatagramProtocol()
|
||||
port = reactor.listenUDP(0, udpprot)
|
||||
udpprot.transport.connect(target_ipaddr, 7)
|
||||
localip = udpprot.transport.getHost().host
|
||||
d = port.stopListening()
|
||||
d.addErrback(log.err)
|
||||
try:
|
||||
# connect() will fail if we're offline (e.g. running tests on a
|
||||
# disconnected laptop), which is fine (localip=None), but we must
|
||||
# still do port.stopListening() or we'll get a DirtyReactorError
|
||||
udpprot.transport.connect(target_ipaddr, 7)
|
||||
localip = udpprot.transport.getHost().host
|
||||
return localip
|
||||
finally:
|
||||
d = port.stopListening()
|
||||
d.addErrback(log.err)
|
||||
except (socket.error, CannotListenError):
|
||||
# no route to that host
|
||||
localip = None
|
||||
|
Loading…
x
Reference in New Issue
Block a user