summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamian Johnson <atagar@torproject.org>2014-12-06 16:45:24 -0800
committerDamian Johnson <atagar@torproject.org>2014-12-06 16:45:24 -0800
commit2ee4e95ab0f2640674c1074ce26e2f09ce9bdf26 (patch)
treee896bd9aa18a85df7814301d8b53e902492a990a
parenta73b17f6db3942626943f8c3cdaa2ff76d1cafed (diff)
Unable to call socket.gethostbyname() when disconnected
A Gentoo ticket notes an interesting stacktrace... https://bugs.gentoo.org/show_bug.cgi?id=527072 ====================================================================== ERROR: test_all_private_policy ---------------------------------------------------------------------- Traceback (most recent call last): File "/tmp/portage/net-libs/stem-1.2.2_p20141018/work/stem-1.2.2_p20141018/test/unit/exit_policy/policy.py", line 115, in test_all_private_policy private_policy = get_config_policy('reject private:%s' % port) File "/tmp/portage/net-libs/stem-1.2.2_p20141018/work/stem-1.2.2_p20141018/stem/exit_policy.py", line 141, in get_config_policy ip_address = socket.gethostbyname(socket.gethostname()) gaierror: [Errno -3] Temporary failure in name resolution ====================================================================== I wasn't able to repro this by simply disconnecting, but oh well. Easy enough to suppress the exception.
-rw-r--r--stem/exit_policy.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/stem/exit_policy.py b/stem/exit_policy.py
index 0b7bea7c..9bc8ccb9 100644
--- a/stem/exit_policy.py
+++ b/stem/exit_policy.py
@@ -136,11 +136,17 @@ def get_config_policy(rules, ip_address = None):
if 'private' in rule:
acceptance = rule.split(' ', 1)[0]
port = rule.split(':', 1)[1]
+ addresses = list(PRIVATE_ADDRESSES)
- if ip_address is None:
- ip_address = socket.gethostbyname(socket.gethostname())
+ if ip_address:
+ addresses.append(ip_address)
+ else:
+ try:
+ addresses.append(socket.gethostbyname(socket.gethostname()))
+ except:
+ pass # we might not have a network connection
- for private_addr in PRIVATE_ADDRESSES + (ip_address,):
+ for private_addr in addresses:
result.append(ExitPolicyRule("%s %s:%s" % (acceptance, private_addr, port)))
else:
result.append(ExitPolicyRule(rule))