fall back to 127.0.0.1 if getaddrinfo fails

This commit is contained in:
Jude Nelson
2018-10-08 13:24:34 -04:00
parent 0c33739310
commit 4550ee3df7

View File

@@ -1045,7 +1045,14 @@ def get_atlas_hostname_stun():
def get_atlas_hostname_addrinfo(rpc_port):
log.debug("Using getnameinfo and getaddrinfo to get my assigned IP address (set 'atlas_hostname' to a valid DNS name or IP address in the config to override)")
hostn = socket.gethostname()
addr_infos = socket.getaddrinfo(hostn, rpc_port)
try:
addr_infos = socket.getaddrinfo(hostn, rpc_port)
except socket.gaierror as gaie:
# hostname doesn't match /etc/hosts, or similar (can happen in chroots)
log.warning('Unable to get addr info for {}: {}. Defaulting to 127.0.0.1'.format(hostn, gaie))
return '127.0.0.1'
real_atlas_hostname = None
for addr_info in addr_infos:
# addr_info[0] == ai_family
@@ -1209,7 +1216,7 @@ def default_blockstack_opts( working_dir, config_file=None ):
RPC_SERVER_IP = atlas_hostname
if atlas_hostname is None and real_atlas_hostname is None:
log.warning('No Atlas hostname given, assuming 127.0.0.1')
log.warning('No Atlas hostname could be determined, assuming 127.0.0.1')
real_atlas_hostname = '127.0.0.1'
RPC_SERVER_IP = real_atlas_hostname