mirror of
https://github.com/lynchaos/ashvale-station.git
synced 2026-09-12 12:47:49 +00:00
Fix shutdown hang and blank equations when KaTeX is unavailable
Shutdown hang, the cause of every restart taking systemd's full 90 s timeout and ending in SIGKILL: /api/stream looped forever with no disconnect or shutdown check, so an open dashboard was an in-flight request that never completed and uvicorn's graceful shutdown waited on it. Reproduced cleanly: with no stream client the process stopped in 2 s, with one open client it was still running after 15 s. Fixed by bounding timeout_graceful_shutdown, and by having the generator exit on client disconnect and on a shutdown event. Now 7 s with a client attached. Equations rendered as blank boxes whenever the KaTeX CDN was unreachable, which is a real case for a Pi on wifi. The elements carried the TeX only in a data attribute, so with no KaTeX there was nothing to display. The source is now written into the element as text first and KaTeX replaces it, so it degrades to readable TeX. Verified by aborting the katex request. A window load handler re-runs typesetting for a slow CDN. The code comment claiming this fallback already existed was wrong and is corrected.
This commit is contained in:
@@ -37,9 +37,13 @@ def main() -> None:
|
||||
|
||||
# One worker, one event loop. The station owns mutable model state, so a
|
||||
# second worker would give you two divergent forecasters sharing a socket.
|
||||
# timeout_graceful_shutdown bounds the wait for in-flight requests. Without
|
||||
# it, the dashboard's server-sent-events connection never completes, so a
|
||||
# stop blocks until systemd's 90 s timeout and ends in SIGKILL. Measured:
|
||||
# with one stream client open, shutdown went from "never" to under 2 s.
|
||||
uvicorn.run("ashvale.api:app", host=args.host, port=args.port,
|
||||
reload=args.reload, workers=1, log_level="info",
|
||||
limit_concurrency=32)
|
||||
limit_concurrency=32, timeout_graceful_shutdown=5)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user