fix(status): /status blocked the event loop and outran its own client timeout
The backend logged 200 OK for polls the client had already timed out on. is_running() waited 2s for an Ollama that ships OFF (now 0.5s), is_available() spawned 'ollama --version' every call and that command blocks ~5s when Ollama is wedged (now cached), and both ran synchronously inside an async def, stalling the event loop on every poll while the UI polls continuously (now to_thread). Measured with Ollama's port blackholed: /status 5.89s -> 0.64s, concurrent GET / stalled -> 0.06s. Poll timeout in nexus_window.py raised 2s -> 5s for margin. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+6
-1
@@ -211,7 +211,12 @@ async def startup_event():
|
||||
@app.get("/status")
|
||||
async def root():
|
||||
try:
|
||||
status = ollama.get_status() if (ollama is not None and hasattr(ollama, "get_status")) else None
|
||||
# to_thread, not a direct call: get_status() does blocking IO (an httpx
|
||||
# request and, once, a subprocess). Awaiting it inline stalled the whole
|
||||
# event loop on every poll - and the UI polls /status continuously, so
|
||||
# the server froze in lockstep with its own health check.
|
||||
status = (await _asyncio.to_thread(ollama.get_status)
|
||||
if (ollama is not None and hasattr(ollama, "get_status")) else None)
|
||||
except Exception:
|
||||
status = None
|
||||
return {"status": "online", "version": VERSION, "ollama": status}
|
||||
|
||||
Reference in New Issue
Block a user