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 <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2023-12-29 08:11:47 -05:00
parent c4d15e40a8
commit 5585884d26
No known key found for this signature in database
GPG Key ID: 5A1EB336DFB4C71B
3 changed files with 6 additions and 0 deletions

View File

@ -307,6 +307,7 @@ class MoonrakerApp:
if self.secure_server is not None: if self.secure_server is not None:
self.secure_server.stop() self.secure_server.stop()
await self.secure_server.close_all_connections() await self.secure_server.close_all_connections()
APIDefinition.reset_cache()
def register_endpoint( def register_endpoint(
self, self,

View File

@ -265,6 +265,10 @@ class APIDefinition:
def get_cache(cls) -> Dict[str, APIDefinition]: def get_cache(cls) -> Dict[str, APIDefinition]:
return cls._cache return cls._cache
@classmethod
def reset_cache(cls) -> None:
cls._cache.clear()
class APITransport: class APITransport:
@property @property
def transport_type(self) -> TransportType: def transport_type(self) -> TransportType:

View File

@ -641,6 +641,7 @@ def main(from_package: bool = True) -> None:
# it is ok to use a blocking sleep here # it is ok to use a blocking sleep here
time.sleep(.5) time.sleep(.5)
logging.info("Attempting Server Restart...") logging.info("Attempting Server Restart...")
del server
event_loop.reset() event_loop.reset()
event_loop.close() event_loop.close()
logging.info("Server Shutdown") logging.info("Server Shutdown")