diff --git a/lbrynet/lbrynet_daemon/Daemon.py b/lbrynet/lbrynet_daemon/Daemon.py index 4ee489f4c..3a3cebbba 100644 --- a/lbrynet/lbrynet_daemon/Daemon.py +++ b/lbrynet/lbrynet_daemon/Daemon.py @@ -9,6 +9,7 @@ import requests import urllib import simplejson as json import textwrap +from requests import exceptions as requests_exceptions from decimal import Decimal from twisted.web import server @@ -128,38 +129,34 @@ class CheckRemoteVersions(object): self.daemon = daemon def __call__(self): - d = self._get_lbrynet_version() + d = threads.deferToThread(self._get_lbrynet_version) + d.addErrback(self._trap_and_log_error, 'lbrynet') d.addCallback(lambda _: self._get_lbryum_version()) + d.addErrback(self._trap_and_log_error, 'lbryum') + d.addErrback(log.fail(), 'Failure checking versions on github') + + def _trap_and_log_error(self, err, module_checked): + # KeyError is thrown by get_version_from_github + # It'd be better to catch the error before trying to parse the response + err.trap(requests_exceptions.RequestException, KeyError) + if err.check(requests_exceptions.RequestException, KeyError): + log.warning("Failed to check latest %s version from github", module_checked) def _get_lbryum_version(self): - try: - version = get_lbryum_version_from_github() - log.info( - "remote lbryum %s > local lbryum %s = %s", - version, lbryum_version, - utils.version_is_greater_than(version, lbryum_version) - ) - self.daemon.git_lbryum_version = version - return defer.succeed(None) - except Exception: - log.info("Failed to get lbryum version from git") - self.daemon.git_lbryum_version = None - return defer.fail(None) + self.daemon.git_lbryum_version = get_lbryum_version_from_github() + log.info( + "remote lbryum %s > local lbryum %s = %s", + self.daemon.git_lbryum_version, lbryum_version, + utils.version_is_greater_than(self.daemon.git_lbryum_version, lbryum_version) + ) def _get_lbrynet_version(self): - try: - version = get_lbrynet_version_from_github() - log.info( - "remote lbrynet %s > local lbrynet %s = %s", - version, lbrynet_version, - utils.version_is_greater_than(version, lbrynet_version) - ) - self.daemon.git_lbrynet_version = version - return defer.succeed(None) - except Exception: - log.info("Failed to get lbrynet version from git") - self.daemon.git_lbrynet_version = None - return defer.fail(None) + self.daemon.git_lbrynet_version = get_lbrynet_version_from_github() + log.info( + "remote lbrynet %s > local lbrynet %s = %s", + self.daemon.git_lbrynet_version, lbrynet_version, + utils.version_is_greater_than(self.daemon.git_lbrynet_version, lbryum_version) + ) class AlwaysSend(object): @@ -304,8 +301,8 @@ class Daemon(AuthJSONRPCServer): log.info("Starting lbrynet-daemon") self.looping_call_manager.start(Checker.INTERNET_CONNECTION, 3600) - self.looping_call_manager.start(Checker.VERSION, 3600 * 12) - self.looping_call_manager.start(Checker.CONNECTION_STATUS, 1) + self.looping_call_manager.start(Checker.VERSION, 1800) + self.looping_call_manager.start(Checker.CONNECTION_STATUS, 30) self.exchange_rate_manager.start() if conf.settings['host_ui']: @@ -1174,12 +1171,12 @@ class Daemon(AuthJSONRPCServer): try: lbrynet_update_available = utils.version_is_greater_than( self.git_lbrynet_version, lbrynet_version) - except AttributeError: + except TypeError: lbrynet_update_available = False try: lbryum_update_available = utils.version_is_greater_than( self.git_lbryum_version, lbryum_version) - except AttributeError: + except TypeError: lbryum_update_available = False msg = { 'platform': platform_info['platform'],