fix(附件): 配置转换超时并重试临时文件清理
将项目文档提取超时配置为 30 秒,适应 Windows 下独立 LibreOffice 配置目录的启动耗时,并记录本地安装与 PATH 配置方法。 附件清理改为异步,遇到转换子进程退出后的短暂文件占用时进行最多 2 秒的重试,保持事件循环可响应并确保上传计数仅释放一次。 本机已安装 LibreOffice 26.8.1.1 并加入用户 PATH。真实 DOC 正文和中文表格提取、正常及强制超时后的目录清理验证通过;全量测试 134 项通过,无跳过。Ruff 静态检查、改动代码格式检查、pip check 和差异检查通过。
This commit is contained in:
1 parent
1b48d0146c
commit
bc9afe2d47
6 files changed
+44
-10
No files matched your search
@@ -194,14 +194,22 @@ class AttachmentStore:
|
||||
raise LimitExceeded()
|
||||
return self.texts[file_id]
|
||||
|
||||
def close(self):
|
||||
async def aclose(self):
|
||||
if not self.closed:
|
||||
self.closed = True
|
||||
self.texts.clear()
|
||||
self.files.clear()
|
||||
self.form.clear()
|
||||
try:
|
||||
self.directory.cleanup()
|
||||
for attempt in range(21):
|
||||
try:
|
||||
self.directory.cleanup()
|
||||
break
|
||||
except PermissionError:
|
||||
# Windows can retain converter file handles briefly after taskkill.
|
||||
if attempt == 20:
|
||||
raise
|
||||
await asyncio.sleep(0.1)
|
||||
finally:
|
||||
if self.on_close is not None:
|
||||
self.on_close()
|
||||
+6
-6
@@ -255,20 +255,20 @@ def create_app(settings: Settings | str = "config.yaml") -> FastAPI:
|
||||
text = body.decode("utf-8")
|
||||
except LimitExceeded:
|
||||
if attachments is not None:
|
||||
attachments.close()
|
||||
await attachments.aclose()
|
||||
return JSONResponse({"error": "RequestTooLarge"}, status_code=413)
|
||||
except InvalidMultipart:
|
||||
attachments.close()
|
||||
await attachments.aclose()
|
||||
return JSONResponse({"error": "InvalidMultipart"}, status_code=400)
|
||||
except UnicodeError:
|
||||
return JSONResponse({"error": "InvalidEncoding"}, status_code=400)
|
||||
except TimeoutError:
|
||||
if attachments is not None:
|
||||
attachments.close()
|
||||
await attachments.aclose()
|
||||
return JSONResponse({"error": "RequestTimeout"}, status_code=408)
|
||||
except BaseException:
|
||||
if attachments is not None:
|
||||
attachments.close()
|
||||
await attachments.aclose()
|
||||
raise
|
||||
|
||||
async def prepare():
|
||||
@@ -357,7 +357,7 @@ def create_app(settings: Settings | str = "config.yaml") -> FastAPI:
|
||||
if session is not None:
|
||||
await session.aclose()
|
||||
if attachments is not None:
|
||||
attachments.close()
|
||||
await attachments.aclose()
|
||||
|
||||
async def prepare_with_budget():
|
||||
async with asyncio.timeout(settings.limits.upstream_timeout_seconds):
|
||||
@@ -371,6 +371,6 @@ def create_app(settings: Settings | str = "config.yaml") -> FastAPI:
|
||||
return JSONResponse({"error": "MiddlewareFailure"}, status_code=502)
|
||||
finally:
|
||||
if attachments is not None and not isinstance(response, ProxyStream):
|
||||
attachments.close()
|
||||
await attachments.aclose()
|
||||
|
||||
return app
|
||||
@@ -267,7 +267,7 @@ class Session:
|
||||
finally:
|
||||
try:
|
||||
if self.attachments is not None:
|
||||
self.attachments.close()
|
||||
await self.attachments.aclose()
|
||||
finally:
|
||||
self.manager.sessions.discard(self)
|
||||
|
||||
|
||||
Reference in new issue
Block a user