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.
This commit is contained in:
Goffi 2026-02-18 17:37:52 +01:00
commit fa937e3e67
2 changed files with 10 additions and 2 deletions

View file

@ -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):

View file

@ -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)