From 6f0a52c1dee82ca114a3f97e9c8616162b4bd71d Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Mon, 23 Nov 2026 17:12:02 +0100 Subject: [PATCH] perf: start up without waiting for tool and terminal servers to answer (#34866) Open WebUI stayed offline at startup until every configured tool server and terminal server had answered or timed out, one after the other, so a single unreachable server kept the app and its health check down for over 20 seconds. Startup now kicks off that fetch in the background and starts serving right away. Anything that needs the tool server details before the fetch lands loads them on demand, as it already did when nothing was cached. If an admin saves the tool or terminal server settings while the startup fetch is still waiting on an unreachable server, the startup fetch can finish last and put back the old list until the next save.
Startup time (until the app answers)BeforeAfter
Tool and terminal server unreachable23.0 s0.6 s
Tool and terminal server answering in 300 ms1.35 s0.6 s
Fixes #34865 --- backend/open_webui/main.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index c208ababa7..f9d01f2a70 100644 --- a/backend/open_webui/main.py +++ b/backend/open_webui/main.py @@ -499,18 +499,22 @@ async def lifespan(app: FastAPI): } ) - log.info('Initializing tool servers...') - try: - await set_tool_servers(mock_request) - log.info('Initialized %s tool server(s)', len(app.state.TOOL_SERVERS)) - except Exception as e: - log.warning(f'Failed to initialize tool servers at startup: {e}') + async def prefetch_tool_servers(): + log.info('Initializing tool servers...') + try: + await set_tool_servers(mock_request) + log.info('Initialized %s tool server(s)', len(app.state.TOOL_SERVERS)) + except Exception as e: + log.warning(f'Failed to initialize tool servers at startup: {e}') - try: - await set_machines(mock_request) - log.info('Initialized %s terminal server(s)', len(app.state.MACHINES)) - except Exception as e: - log.warning(f'Failed to initialize terminal servers at startup: {e}') + try: + await set_machines(mock_request) + log.info('Initialized %s terminal server(s)', len(app.state.MACHINES)) + except Exception as e: + log.warning(f'Failed to initialize terminal servers at startup: {e}') + + # Don't hold startup on unreachable servers + app.state.prefetch_tool_servers = asyncio.create_task(prefetch_tool_servers()) # Mark application as ready to accept traffic from a startup perspective. if license_task: @@ -540,6 +544,9 @@ async def lifespan(app: FastAPI): if hasattr(app.state, 'redis_task_heartbeat'): app.state.redis_task_heartbeat.cancel() + if hasattr(app.state, 'prefetch_tool_servers'): + app.state.prefetch_tool_servers.cancel() + app.state.periodic_socket_authentication.cancel() app.state.periodic_usage_pool_cleanup.cancel() app.state.periodic_session_pool_cleanup.cancel()