diff --git a/CHANGELOG.md b/CHANGELOG.md index e391c7073..78c35915d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,8 +18,9 @@ at anytime. * ### Fixed - * - * + * Fix multiple reactor.stop() calls + * Properly shut down lbryum wallet from lbrynet + * Set LBRYumWallet.config upon initialization, fixes attribute error ### Deprecated * diff --git a/lbrynet/core/Wallet.py b/lbrynet/core/Wallet.py index 791fac047..eec5057eb 100644 --- a/lbrynet/core/Wallet.py +++ b/lbrynet/core/Wallet.py @@ -868,6 +868,7 @@ class LBRYumWallet(Wallet): def __init__(self, storage, config=None): Wallet.__init__(self, storage) self._config = config + self.config = make_config(self._config) self.network = None self.wallet = None self.is_first_run = False @@ -885,7 +886,6 @@ class LBRYumWallet(Wallet): def _start(self): network_start_d = defer.Deferred() - self.config = make_config(self._config) def setup_network(): self.network = Network(self.config) @@ -938,8 +938,12 @@ class LBRYumWallet(Wallet): self.network = None d.callback(True) + if self.wallet: + self.wallet.stop_threads() + log.info("Stopped wallet") if self.network: self.network.stop() + log.info("Stopped connection to lbryum server") stop_check = task.LoopingCall(check_stopped) stop_check.start(.1) diff --git a/lbrynet/dht/protocol.py b/lbrynet/dht/protocol.py index f50257099..f7b9f1304 100644 --- a/lbrynet/dht/protocol.py +++ b/lbrynet/dht/protocol.py @@ -178,22 +178,7 @@ class KademliaProtocol(protocol.DatagramProtocol): df.callback((message, address)) elif isinstance(message, msgtypes.ErrorMessage): # The RPC request raised a remote exception; raise it locally - if message.exceptionType.startswith('exceptions.'): - exceptionClassName = message.exceptionType[11:] - else: - localModuleHierarchy = self.__module__.split('.') - remoteHierarchy = message.exceptionType.split('.') - # strip the remote hierarchy - while remoteHierarchy[0] == localModuleHierarchy[0]: - remoteHierarchy.pop(0) - localModuleHierarchy.pop(0) - exceptionClassName = '.'.join(remoteHierarchy) - remoteException = None - try: - exec 'remoteException = %s("%s")' % (exceptionClassName, message.response) - except Exception: - # We could not recreate the exception; create a generic one - remoteException = Exception(message.response) + remoteException = Exception(message.response) df.errback(remoteException) else: # We got a result from the RPC diff --git a/lbrynet/lbrynet_daemon/Daemon.py b/lbrynet/lbrynet_daemon/Daemon.py index 4ee9140ac..7064ef83c 100644 --- a/lbrynet/lbrynet_daemon/Daemon.py +++ b/lbrynet/lbrynet_daemon/Daemon.py @@ -169,8 +169,6 @@ class Daemon(AuthJSONRPCServer): def __init__(self, root, analytics_manager): AuthJSONRPCServer.__init__(self, conf.settings['use_auth_http']) - reactor.addSystemEventTrigger('before', 'shutdown', self._shutdown) - self.allowed_during_startup = [ 'stop', 'status', 'version', # delete these once they are fully removed: @@ -239,6 +237,8 @@ class Daemon(AuthJSONRPCServer): @defer.inlineCallbacks def setup(self, launch_ui): + reactor.addSystemEventTrigger('before', 'shutdown', self._shutdown) + self._modify_loggly_formatter() @defer.inlineCallbacks @@ -1281,6 +1281,7 @@ class Daemon(AuthJSONRPCServer): """ return self.jsonrpc_daemon_stop() + @defer.inlineCallbacks def jsonrpc_daemon_stop(self): """ Stop lbrynet-daemon @@ -1289,13 +1290,10 @@ class Daemon(AuthJSONRPCServer): (string) Shutdown message """ - def _display_shutdown_message(): - log.info("Shutting down lbrynet daemon") - - d = self._shutdown() - d.addCallback(lambda _: _display_shutdown_message()) - d.addCallback(lambda _: reactor.callLater(0.0, reactor.stop)) - return self._render_response("Shutting down") + log.info("Shutting down lbrynet daemon") + response = yield self._render_response("Shutting down") + reactor.callLater(0.1, reactor.fireSystemEvent, "shutdown") + defer.returnValue(response) @defer.inlineCallbacks def jsonrpc_file_list(self, **kwargs): diff --git a/lbrynet/lbrynet_daemon/DaemonControl.py b/lbrynet/lbrynet_daemon/DaemonControl.py index 067590e7a..340445824 100644 --- a/lbrynet/lbrynet_daemon/DaemonControl.py +++ b/lbrynet/lbrynet_daemon/DaemonControl.py @@ -120,22 +120,15 @@ def start_server_and_listen(launchui, use_auth, analytics_manager, max_tries=5): analytics_manager: to send analytics """ analytics_manager.send_server_startup() - tries = 1 - while tries < max_tries: - log.info('Making attempt %s / %s to startup', tries, max_tries) - try: - daemon_server = DaemonServer(analytics_manager) - yield daemon_server.start(use_auth, launchui) - analytics_manager.send_server_startup_success() - break - except Exception as e: - log.exception('Failed to startup') - yield daemon_server.stop() - analytics_manager.send_server_startup_error(str(e)) - tries += 1 - else: - log.warn("Exceeded max tries to start up, stopping") - reactor.callFromThread(reactor.stop) + daemon_server = DaemonServer(analytics_manager) + try: + yield daemon_server.start(use_auth, launchui) + analytics_manager.send_server_startup_success() + except Exception as e: + log.exception('Failed to startup') + yield daemon_server.stop() + analytics_manager.send_server_startup_error(str(e)) + reactor.fireSystemEvent("shutdown") if __name__ == "__main__": diff --git a/lbrynet/lbrynet_daemon/DaemonServer.py b/lbrynet/lbrynet_daemon/DaemonServer.py index 1af7045de..c246287cb 100644 --- a/lbrynet/lbrynet_daemon/DaemonServer.py +++ b/lbrynet/lbrynet_daemon/DaemonServer.py @@ -55,6 +55,7 @@ class DaemonServer(object): if self.server_port is not None: yield self.server_port.stopListening() + def get_site_base(use_auth, root): if use_auth: log.info("Using authenticated API") diff --git a/lbrynet/lbrynet_daemon/ExchangeRateManager.py b/lbrynet/lbrynet_daemon/ExchangeRateManager.py index e0ec2459b..b553ef5be 100644 --- a/lbrynet/lbrynet_daemon/ExchangeRateManager.py +++ b/lbrynet/lbrynet_daemon/ExchangeRateManager.py @@ -2,7 +2,7 @@ import time import requests import logging import json -from twisted.internet import defer, threads, reactor +from twisted.internet import defer, threads from twisted.internet.task import LoopingCall from lbrynet import conf @@ -167,7 +167,6 @@ def get_default_market_feed(currency_pair): class ExchangeRateManager(object): def __init__(self): - reactor.addSystemEventTrigger('before', 'shutdown', self.stop) self.market_feeds = [ get_default_market_feed(currency_pair) for currency_pair in CURRENCY_PAIRS]