From fa937e3e67d5133d239c7ca0f044211d8d268b2c Mon Sep 17 00:00:00 2001 From: Goffi Date: Wed, 18 Feb 2026 17:37:52 +0100 Subject: [PATCH] core(launcher): Force exit on early exception: The backend was not properly exiting in case of early exception (e.g. configuration error). It seems to be related to the use of the `@aio` decorator, but couldn't find the exact issue with loop. The use of `os._exit` is a workaround for now, until the fix is inspected more deeply and properly fixed. --- libervia/backend/core/launcher.py | 10 ++++++++-- libervia/backend/core/main.py | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/libervia/backend/core/launcher.py b/libervia/backend/core/launcher.py index c8e83b0a..7bb2f6d1 100644 --- a/libervia/backend/core/launcher.py +++ b/libervia/backend/core/launcher.py @@ -312,10 +312,16 @@ class Launcher: runner.run() if runner._exitSignal is not None: app._exitWithSignal(runner._exitSignal) + # FIXME: The loop is not closing correctly as soon as + # libervia.backend.tools.utils.aio decoractor is used. Asyncio loop doesn't + # seem to have any task left, and reactor is stopped, but there is still + # something preventing proper exit. `os._exit` is not great, but currently + # the way to actually close the backend in this case. This needs further + # investigation. try: - sys.exit(app._exit_code) + os._exit(app._exit_code) except AttributeError: - pass + os._exit(C.EXIT_ERROR) @classmethod def run(cls): diff --git a/libervia/backend/core/main.py b/libervia/backend/core/main.py index f475d7cb..c8cf7221 100644 --- a/libervia/backend/core/main.py +++ b/libervia/backend/core/main.py @@ -284,9 +284,11 @@ class LiberviaBackend(service.Service): f"Configuration error, please check and fix your configuration: {e}" ) self.stop(exit_code=C.EXIT_BAD_ARG) + return except Exception: log.exception(f"Could not initialize backend") self.stop(exit_code=C.EXIT_ERROR) + return self._add_base_menus() self.init_pre_script.callback(None)