From 63a77928b95ef7ef17455dda155059fd50b3b545 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Sat, 5 Dec 2026 05:06:34 +0100 Subject: [PATCH] fix: Docling uploads never finish and hold a worker thread when docling-serve stalls (#35639) With Docling as the content extraction engine, an upload whose conversion never finished, or whose status check a proxy never answered, stayed processing forever and kept its worker thread until a restart. Enough of them used up every thread and the whole app stopped answering. A conversion now fails with a clear timeout error once it runs past the new API Timeout in Admin Settings > Documents (DOCLING_API_TIMEOUT, 300 seconds by default, like the MinerU one), and a request to docling-serve that gets no answer fails after the same time. Conversions that take longer than that now fail until the timeout is raised, and 0 removes the limit. Fixes #35625 --- backend/open_webui/config.py | 3 +++ backend/open_webui/retrieval/loaders/main.py | 23 ++++++++++++++++--- backend/open_webui/retrieval/utils.py | 1 + backend/open_webui/routers/retrieval.py | 4 ++++ .../admin/Settings/Documents.svelte | 16 +++++++++++++ src/lib/i18n/locales/en-US/translation.json | 2 ++ 6 files changed, 46 insertions(+), 3 deletions(-) diff --git a/backend/open_webui/config.py b/backend/open_webui/config.py index 50e232af29..456ca4b851 100644 --- a/backend/open_webui/config.py +++ b/backend/open_webui/config.py @@ -918,6 +918,8 @@ DOCLING_SERVER_URL = os.getenv('DOCLING_SERVER_URL', 'http://docling:5001') DOCLING_API_KEY = os.getenv('DOCLING_API_KEY', '') +DOCLING_API_TIMEOUT = os.getenv('DOCLING_API_TIMEOUT', '300') + docling_params = os.getenv('DOCLING_PARAMS', '') try: docling_params = JSONCodec.loads(docling_params) @@ -3066,6 +3068,7 @@ DEFAULT_CONFIG = { 'rag.tika_server_version': TIKA_SERVER_VERSION, 'rag.docling_server_url': DOCLING_SERVER_URL, 'rag.docling_api_key': DOCLING_API_KEY, + 'rag.docling_api_timeout': DOCLING_API_TIMEOUT, 'rag.docling_params': DOCLING_PARAMS, 'rag.document_intelligence_endpoint': DOCUMENT_INTELLIGENCE_ENDPOINT, 'rag.document_intelligence_key': DOCUMENT_INTELLIGENCE_KEY, diff --git a/backend/open_webui/retrieval/loaders/main.py b/backend/open_webui/retrieval/loaders/main.py index 36b9b02667..30ae6bf4ec 100644 --- a/backend/open_webui/retrieval/loaders/main.py +++ b/backend/open_webui/retrieval/loaders/main.py @@ -247,9 +247,10 @@ class TikaLoader: class DoclingLoader: - def __init__(self, url, api_key=None, file_path=None, mime_type=None, params=None): + def __init__(self, url, api_key=None, file_path=None, mime_type=None, params=None, timeout: int | None = 300): self.url = url.rstrip('/') self.api_key = api_key + self.timeout = timeout self.file_path = file_path self.mime_type = mime_type @@ -282,12 +283,19 @@ class DoclingLoader: }, headers=headers, verify=AIOHTTP_CLIENT_SESSION_SSL, + timeout=self.timeout, ) + deadline = time.monotonic() + self.timeout if self.timeout else None while r.ok and r.json()['task_status'] in ['pending', 'started']: + if deadline and time.monotonic() > deadline: + raise Exception(f'Error calling Docling: conversion timed out after {self.timeout} seconds') time.sleep(2) r = requests.get( - f'{self.url}/v1/status/poll/{r.json()["task_id"]}', headers=headers, verify=AIOHTTP_CLIENT_SESSION_SSL + f'{self.url}/v1/status/poll/{r.json()["task_id"]}', + headers=headers, + verify=AIOHTTP_CLIENT_SESSION_SSL, + timeout=self.timeout, ) if r.ok: @@ -295,7 +303,10 @@ class DoclingLoader: if task['task_status'] == 'failure': raise Exception(f'Error calling Docling: conversion failed - {task.get("error_message")}') r = requests.get( - f'{self.url}/v1/result/{task["task_id"]}', headers=headers, verify=AIOHTTP_CLIENT_SESSION_SSL + f'{self.url}/v1/result/{task["task_id"]}', + headers=headers, + verify=AIOHTTP_CLIENT_SESSION_SSL, + timeout=self.timeout, ) if r.ok: @@ -657,12 +668,18 @@ class Loader: log.error('Invalid DOCLING_PARAMS format, expected JSON object') params = {} + # 0 or empty disables the limit + try: + docling_timeout = int(self.config['rag.docling_api_timeout'] or 0) or None + except ValueError: + docling_timeout = 300 loader = DoclingLoader( url=self.config['rag.docling_server_url'], api_key=self.config['rag.docling_api_key'], file_path=file_path, mime_type=file_content_type, params=params, + timeout=docling_timeout, ) elif ( self.engine == 'document_intelligence' diff --git a/backend/open_webui/retrieval/utils.py b/backend/open_webui/retrieval/utils.py index e9e3a16cbf..6679cf974f 100644 --- a/backend/open_webui/retrieval/utils.py +++ b/backend/open_webui/retrieval/utils.py @@ -192,6 +192,7 @@ async def get_content_from_url(request, url: str, *, config: dict | None = None) 'rag.datalab_marker_strip_existing_ocr', 'rag.datalab_marker_use_llm', 'rag.docling_api_key', + 'rag.docling_api_timeout', 'rag.docling_params', 'rag.docling_server_url', 'rag.document_intelligence_endpoint', diff --git a/backend/open_webui/routers/retrieval.py b/backend/open_webui/routers/retrieval.py index 2e861f3981..c01f420ff4 100644 --- a/backend/open_webui/routers/retrieval.py +++ b/backend/open_webui/routers/retrieval.py @@ -270,6 +270,7 @@ RETRIEVAL_CONFIG_KEYS = { 'DATALAB_MARKER_USE_LLM': 'rag.datalab_marker_use_llm', 'DDGS_BACKEND': 'web.search.ddgs_backend', 'DOCLING_API_KEY': 'rag.docling_api_key', + 'DOCLING_API_TIMEOUT': 'rag.docling_api_timeout', 'DOCLING_PARAMS': 'rag.docling_params', 'DOCLING_SERVER_URL': 'rag.docling_server_url', 'DOCUMENT_INTELLIGENCE_ENDPOINT': 'rag.document_intelligence_endpoint', @@ -649,6 +650,7 @@ async def get_rag_config(request: Request, user=Depends(get_admin_user)): 'TIKA_SERVER_VERSION': config['rag.tika_server_version'], 'DOCLING_SERVER_URL': config['rag.docling_server_url'], 'DOCLING_API_KEY': config['rag.docling_api_key'], + 'DOCLING_API_TIMEOUT': config['rag.docling_api_timeout'], 'DOCLING_PARAMS': config['rag.docling_params'], 'DOCUMENT_INTELLIGENCE_ENDPOINT': config['rag.document_intelligence_endpoint'], 'DOCUMENT_INTELLIGENCE_KEY': config['rag.document_intelligence_key'], @@ -901,6 +903,7 @@ class ConfigForm(BaseModel): TIKA_SERVER_VERSION: str | None = None DOCLING_SERVER_URL: str | None = None DOCLING_API_KEY: str | None = None + DOCLING_API_TIMEOUT: int | None = None DOCLING_PARAMS: dict | None = None DOCUMENT_INTELLIGENCE_ENDPOINT: str | None = None DOCUMENT_INTELLIGENCE_KEY: str | None = None @@ -1118,6 +1121,7 @@ async def update_rag_config(request: Request, form_data: ConfigForm, user=Depend 'TIKA_SERVER_VERSION': config['rag.tika_server_version'], 'DOCLING_SERVER_URL': config['rag.docling_server_url'], 'DOCLING_API_KEY': config['rag.docling_api_key'], + 'DOCLING_API_TIMEOUT': config['rag.docling_api_timeout'], 'DOCLING_PARAMS': config['rag.docling_params'], 'DOCUMENT_INTELLIGENCE_ENDPOINT': config['rag.document_intelligence_endpoint'], 'DOCUMENT_INTELLIGENCE_KEY': config['rag.document_intelligence_key'], diff --git a/src/lib/components/admin/Settings/Documents.svelte b/src/lib/components/admin/Settings/Documents.svelte index 5f00e1c678..4cb38f1d0f 100644 --- a/src/lib/components/admin/Settings/Documents.svelte +++ b/src/lib/components/admin/Settings/Documents.svelte @@ -130,6 +130,7 @@ TIKA_SERVER_VERSION: $i18n.t('settings.admin.documents.tikaServerVersion.label'), DOCLING_SERVER_URL: $i18n.t('settings.admin.documents.doclingServerUrl.label'), DOCLING_API_KEY: $i18n.t('settings.admin.documents.doclingApiKey.label'), + DOCLING_API_TIMEOUT: $i18n.t('settings.admin.documents.doclingApiTimeout.label'), DOCLING_PARAMS: $i18n.t('settings.admin.documents.doclingParams.label'), DOCUMENT_INTELLIGENCE_ENDPOINT: $i18n.t('settings.admin.documents.endpoint.label'), DOCUMENT_INTELLIGENCE_KEY: $i18n.t('settings.admin.documents.documentIntelligenceKey.label'), @@ -912,6 +913,21 @@ + + + +