mirror of
https://github.com/open-webui/open-webui.git
synced 2026-12-05 02:57:57 -05:00
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
This commit is contained in:
1 parent
83b692aac2
commit
63a77928b9
6 files changed
+46
-3
No files matched your search
@@ -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,
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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'],
|
||||
|
||||
@@ -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 @@
|
||||
</AdminSettingField>
|
||||
</div>
|
||||
|
||||
<AdminSettingRow
|
||||
label={$i18n.t('settings.admin.documents.doclingApiTimeout.label')}
|
||||
description={$i18n.t('settings.admin.documents.doclingApiTimeout.description')}
|
||||
let:labelId
|
||||
>
|
||||
<input
|
||||
id={`${labelId}-control`}
|
||||
class="w-16 rounded-lg border border-base-100/50 bg-base-50/40 px-2 text-right text-xs text-base-700 outline-hidden transition-colors focus:border-blue-400 dark:border-base-0/[0.04] dark:bg-base-0/[0.03] dark:text-base-300 dark:focus:border-blue-500"
|
||||
type="number"
|
||||
min="0"
|
||||
bind:value={RAGConfig.DOCLING_API_TIMEOUT}
|
||||
placeholder="300"
|
||||
/>
|
||||
</AdminSettingRow>
|
||||
|
||||
<AdminSettingField
|
||||
label={$i18n.t('settings.admin.documents.doclingParams.label')}
|
||||
description={$i18n.t('settings.admin.documents.doclingParams.description')}
|
||||
|
||||
@@ -3686,6 +3686,8 @@
|
||||
"settings.admin.documents.disableImageExtraction.label": "Disable Image Extraction",
|
||||
"settings.admin.documents.doclingApiKey.description": "API key sent to Docling.",
|
||||
"settings.admin.documents.doclingApiKey.label": "API Key",
|
||||
"settings.admin.documents.doclingApiTimeout.description": "Maximum time in seconds to wait for Docling to convert a file.",
|
||||
"settings.admin.documents.doclingApiTimeout.label": "API Timeout",
|
||||
"settings.admin.documents.doclingParams.description": "Additional Docling parameters in JSON format.",
|
||||
"settings.admin.documents.doclingParams.label": "Parameters",
|
||||
"settings.admin.documents.doclingServerUrl.description": "Docling service endpoint used for parsing.",
|
||||
|
||||
Reference in new issue
Block a user