From 2a18dc98ac69eb200a17f53ddd3eaab5ce8d4f44 Mon Sep 17 00:00:00 2001 From: Jacob Leksan <63938553+jmleksan@users.noreply.github.com> Date: Fri, 8 May 2026 12:20:11 -0400 Subject: [PATCH] Implement asynchronous database ping for health checks (#24380) --- backend/open_webui/main.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index e4ee823b4f..19227b6b9e 100644 --- a/backend/open_webui/main.py +++ b/backend/open_webui/main.py @@ -2812,6 +2812,14 @@ async def get_opensearch_xml(): return Response(content=xml_content, media_type='application/xml') +def _sync_db_ping() -> None: + ScopedSession.execute(text('SELECT 1;')).all() + + +async def async_db_ping() -> None: + await asyncio.to_thread(_sync_db_ping) + + @app.get('/health') async def healthcheck(): return {'status': True} @@ -2833,7 +2841,7 @@ async def readiness_check(): # Check database connectivity try: - ScopedSession.execute(text('SELECT 1;')).all() + await async_db_ping() except Exception as e: log.warning(f'Readiness check DB ping failed: {e!r}') raise HTTPException( @@ -2860,7 +2868,7 @@ async def readiness_check(): @app.get('/health/db') async def healthcheck_with_db(): - ScopedSession.execute(text('SELECT 1;')).all() + await async_db_ping() return {'status': True}