mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-15 21:45:10 +00:00
fix(api): stop a service's sys.exit from killing the serve process
Catch SystemExit at service import, in the heartbeat task, the 5xx middleware, search, samples and chapters, and answer it as SERVICE_ERROR.
This commit is contained in:
@@ -121,3 +121,11 @@ def test_overdue_staged_service_applies_while_busy(service_dir: Path, monkeypatc
|
||||
assert services.apply_pending(busy={"FOO"}) == ["FOO"]
|
||||
assert services.MODULES["FOO"].VERSION == 2
|
||||
assert services.PENDING == set() and "FOO" not in services.PENDING_SINCE
|
||||
|
||||
|
||||
def test_service_that_exits_on_import_fails_its_reload_only(service_dir: Path):
|
||||
"""A service calling sys.exit at import time is a load error, not a stop of the process."""
|
||||
(service_dir / "FOO" / "__init__.py").write_text("import sys\nsys.exit(1)\n")
|
||||
os.utime(service_dir / "FOO" / "__init__.py", (time.time() + 9, time.time() + 9))
|
||||
services.reload_services(["FOO"])
|
||||
assert services.LOAD_ERRORS and services.LOAD_ERRORS[-1].startswith("FOO: failed to import - SystemExit")
|
||||
|
||||
Reference in New Issue
Block a user