From 56ecdb63ae576b48685ed1e2aa75739bdc0d3d9f Mon Sep 17 00:00:00 2001 From: Nexory Date: Sat, 30 May 2026 18:00:22 +0200 Subject: [PATCH] chore: improve variable naming per review feedback - Rename _daemon_done_cb to log_unexpected_cleanup_task_exit (descriptive vs abbreviated, no underscore-prefix on what is logically a helper, not private state). - Replace the for-loop with two-letter shorthand variables (_attr, _t) with explicit hasattr checks matching the existing redis_task_command_listener shutdown pattern at line 754 exactly. No behavior change. Addresses naming feedback on #25222. --- backend/open_webui/main.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index 5b86523534..af21be0c2e 100644 --- a/backend/open_webui/main.py +++ b/backend/open_webui/main.py @@ -660,7 +660,7 @@ async def lifespan(app: FastAPI): limiter = anyio.to_thread.current_default_thread_limiter() limiter.total_tokens = THREAD_POOL_SIZE - def _daemon_done_cb(task: asyncio.Task) -> None: + def log_unexpected_cleanup_task_exit(task: asyncio.Task) -> None: # `asyncio.create_task` discards exceptions on unreferenced tasks; without # this callback a dead cleanup loop only surfaces as a delayed # "Task exception was never retrieved" WARNING at GC time, by which point @@ -669,7 +669,7 @@ async def lifespan(app: FastAPI): # immediate, alertable signal at the moment of death. if not task.cancelled() and task.exception() is not None: log.error( - 'Background daemon task %s exited unexpectedly: %r ' + 'Background cleanup task %s exited unexpectedly: %r ' '— pool cleanup has stopped for the remaining lifetime of the process.', task.get_name(), task.exception(), @@ -679,12 +679,12 @@ async def lifespan(app: FastAPI): app.state.periodic_usage_cleanup_task = asyncio.create_task( periodic_usage_pool_cleanup(), name='periodic_usage_pool_cleanup' ) - app.state.periodic_usage_cleanup_task.add_done_callback(_daemon_done_cb) + app.state.periodic_usage_cleanup_task.add_done_callback(log_unexpected_cleanup_task_exit) app.state.periodic_session_cleanup_task = asyncio.create_task( periodic_session_pool_cleanup(), name='periodic_session_pool_cleanup' ) - app.state.periodic_session_cleanup_task.add_done_callback(_daemon_done_cb) + app.state.periodic_session_cleanup_task.add_done_callback(log_unexpected_cleanup_task_exit) from open_webui.utils.automations import scheduler_worker_loop @@ -763,10 +763,10 @@ async def lifespan(app: FastAPI): # the tasks are destroyed mid-await and asyncio emits a # "Task was destroyed but it is pending!" warning on every clean restart, # which trains operators to ignore that warning and masks real failures. - for _attr in ('periodic_usage_cleanup_task', 'periodic_session_cleanup_task'): - _t = getattr(app.state, _attr, None) - if _t is not None: - _t.cancel() + if hasattr(app.state, 'periodic_usage_cleanup_task'): + app.state.periodic_usage_cleanup_task.cancel() + if hasattr(app.state, 'periodic_session_cleanup_task'): + app.state.periodic_session_cleanup_task.cancel() app = FastAPI(