diff --git a/lbry/lbry/extras/daemon/Daemon.py b/lbry/lbry/extras/daemon/Daemon.py index 5552ba0a6..f54932ab7 100644 --- a/lbry/lbry/extras/daemon/Daemon.py +++ b/lbry/lbry/extras/daemon/Daemon.py @@ -474,6 +474,8 @@ class Daemon(metaclass=JSONRPCServerType): self.component_startup_task.cancel() log.info("stopped api components") if shutdown_runner: + self.rpc_runner.app.on_shutdown.freeze() + self.streaming_runner.app.on_shutdown.freeze() await self.rpc_runner.shutdown() await self.streaming_runner.shutdown() await self.rpc_runner.cleanup() diff --git a/lbry/tests/unit/test_cli.py b/lbry/tests/unit/test_cli.py index 39fe0ee3a..7abf2dcb6 100644 --- a/lbry/tests/unit/test_cli.py +++ b/lbry/tests/unit/test_cli.py @@ -7,6 +7,7 @@ from io import StringIO from unittest import TestCase from types import SimpleNamespace from contextlib import asynccontextmanager +from unittest.mock import patch import docopt from torba.testcase import AsyncioTestCase @@ -193,6 +194,15 @@ class CLITest(AsyncioTestCase): "Could not connect to daemon. Are you sure it's running?" ) + @patch.object(Daemon, 'start', spec=Daemon, wraps=Daemon.start) + def test_keyboard_interrupt_handling(self, mock_daemon_start): + def side_effect(): + raise KeyboardInterrupt + + mock_daemon_start.side_effect = side_effect + self.shell(["start"]) + mock_daemon_start.assert_called_once() + class DaemonDocsTests(TestCase):