Merge branch 'mirgee-check_connection_bypass_dns'

This commit is contained in:
Jack Robison 2017-10-31 12:24:56 -04:00
commit b9e03a7f13
No known key found for this signature in database
GPG key ID: 284699E7404E3CFF
2 changed files with 20 additions and 7 deletions

View file

@ -119,6 +119,7 @@ at anytime.
### Fixed
* Fixed `transaction_list` doc string
* Fixed ([in lbryum](https://github.com/lbryio/lbryum/pull/156)) batched queries responsible for making transaction and tip histories slow
* Fixed daemon refusing to start if DNS cannot resolve lbry.io domain.
### Changed
* Bumped `lbryum` requirement to 3.1.8 [see changelog](https://github.com/lbryio/lbryum/blob/master/CHANGELOG.md#318---2017-09-20)

View file

@ -94,18 +94,30 @@ def obfuscate(plain):
return base64.b64encode(plain).encode('rot13')
def check_connection(server="lbry.io", port=80):
def check_connection(server="lbry.io", port=80, timeout=2):
"""Attempts to open a socket to server:port and returns True if successful."""
log.debug('Checking connection to %s:%s', server, port)
try:
log.debug('Checking connection to %s:%s', server, port)
host = socket.gethostbyname(server)
s = socket.create_connection((host, port), 2)
server = socket.gethostbyname(server)
socket.create_connection((server, port), timeout)
log.debug('Connection successful')
return True
except (socket.gaierror, socket.herror) as ex:
log.warning("Failed to connect to %s:%s. Unable to resolve domain. Trying to bypass DNS",
server, port)
try:
server = "8.8.8.8"
port = 53
socket.create_connection((server, port), timeout)
log.debug('Connection successful')
return True
except Exception as ex:
log.error("Failed to connect to %s:%s. Maybe the internet connection is not working",
server, port)
return False
except Exception as ex:
log.info(
"Failed to connect to %s:%s. Maybe the internet connection is not working",
server, port, exc_info=True)
log.error("Failed to connect to %s:%s. Maybe the internet connection is not working",
server, port)
return False