From 5585884d262896ceeeec565b9edad7629d6c3a73 Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Fri, 29 Dec 2023 08:11:47 -0500 Subject: [PATCH] app: resolve soft restart issues Clear the API cache when closing to purge stale callbacks. In addition, explicitly delte the server object after the eventloop stops. Signed-off-by: Eric Callahan --- moonraker/app.py | 1 + moonraker/common.py | 4 ++++ moonraker/server.py | 1 + 3 files changed, 6 insertions(+) diff --git a/moonraker/app.py b/moonraker/app.py index 47d2fb5..5ef8ae2 100644 --- a/moonraker/app.py +++ b/moonraker/app.py @@ -307,6 +307,7 @@ class MoonrakerApp: if self.secure_server is not None: self.secure_server.stop() await self.secure_server.close_all_connections() + APIDefinition.reset_cache() def register_endpoint( self, diff --git a/moonraker/common.py b/moonraker/common.py index d0c63d3..d47871c 100644 --- a/moonraker/common.py +++ b/moonraker/common.py @@ -265,6 +265,10 @@ class APIDefinition: def get_cache(cls) -> Dict[str, APIDefinition]: return cls._cache + @classmethod + def reset_cache(cls) -> None: + cls._cache.clear() + class APITransport: @property def transport_type(self) -> TransportType: diff --git a/moonraker/server.py b/moonraker/server.py index b290728..dfd3822 100755 --- a/moonraker/server.py +++ b/moonraker/server.py @@ -641,6 +641,7 @@ def main(from_package: bool = True) -> None: # it is ok to use a blocking sleep here time.sleep(.5) logging.info("Attempting Server Restart...") + del server event_loop.reset() event_loop.close() logging.info("Server Shutdown")