mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-02 18:33:33 -05:00
fix: prevent worker death during document upload by using run_coroutine_threadsafe (#21158)
* fix: prevent worker death during document upload by using run_coroutine_threadsafe Replace asyncio.run() with asyncio.run_coroutine_threadsafe() in save_docs_to_vector_db() to prevent uvicorn worker health check failures. The issue: asyncio.run() creates a new event loop and blocks the thread completely, preventing the worker from responding to health checks during long-running embedding operations (>5 seconds default timeout). The fix: Schedule the async embedding work on the main event loop using run_coroutine_threadsafe(). This keeps the main loop responsive to health check pings while the sync caller waits for the result. Changes: - main.py: Store main event loop reference in app.state.main_loop at startup - retrieval.py: Use run_coroutine_threadsafe() instead of asyncio.run() https://claude.ai/code/session_01UQSYvSTkXb57sFb7M85Kcw * add env var --------- Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -591,6 +591,10 @@ https://github.com/open-webui/open-webui
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
# Store reference to main event loop for sync->async calls (e.g., embedding generation)
|
||||
# This allows sync functions to schedule work on the main loop without blocking health checks
|
||||
app.state.main_loop = asyncio.get_running_loop()
|
||||
|
||||
app.state.instance_id = INSTANCE_ID
|
||||
start_logger()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user