diff --git a/lbry/extras/daemon/daemon.py b/lbry/extras/daemon/daemon.py index 5a4373dea..8f0ae21ff 100644 --- a/lbry/extras/daemon/daemon.py +++ b/lbry/extras/daemon/daemon.py @@ -557,6 +557,14 @@ class Daemon(metaclass=JSONRPCServerType): await self.component_manager.stop() else: self.component_startup_task.cancel() + # the wallet component might have not started + try: + wallet_component = self.component_manager.get_actual_component('wallet') + except NameError: + pass + else: + await wallet_component.stop() + await self.component_manager.stop() log.info("stopped api components") await self.rpc_runner.cleanup() await self.streaming_runner.cleanup() diff --git a/lbry/wallet/database.py b/lbry/wallet/database.py index fda8ace77..a1c9e4516 100644 --- a/lbry/wallet/database.py +++ b/lbry/wallet/database.py @@ -145,7 +145,7 @@ class AIOSQLite: self.waiting_reads_metric.inc() self.read_count_metric.inc() try: - while self.writers: # more writes can come in while we are waiting for the first + while self.writers and not self._closing: # more writes can come in while we are waiting for the first if not urgent_read and still_waiting and self.urgent_read_done.is_set(): # throttle the writes if they pile up self.urgent_read_done.clear() @@ -153,6 +153,8 @@ class AIOSQLite: # wait until the running writes have finished await self.read_ready.wait() still_waiting = True + if self._closing: + raise asyncio.CancelledError return await asyncio.get_event_loop().run_in_executor( self.reader_executor, read_only_fn, sql, parameters ) @@ -195,6 +197,8 @@ class AIOSQLite: self.read_ready.clear() try: async with self.write_lock: + if self._closing: + raise asyncio.CancelledError return await asyncio.get_event_loop().run_in_executor( self.writer_executor, lambda: self.__run_transaction(fun, *args, **kwargs) ) @@ -230,6 +234,8 @@ class AIOSQLite: self.read_ready.clear() try: async with self.write_lock: + if self._closing: + raise asyncio.CancelledError return await asyncio.get_event_loop().run_in_executor( self.writer_executor, self.__run_transaction_with_foreign_keys_disabled, fun, args, kwargs )