🐛 fix: 保留合并结果并重试上传收尾校验

* 校验读取中断时有限重试,保留合并文件供再次完成上传\n* 复用完整合并结果,损坏结果仍重建并核对完整内容\n* 固定有限轮询重试的前端版本并记录回归验证
This commit is contained in:
orion committed 2026-10-06 02:01:53 +08:00
1 parent 8af45a70f6
commit 75dc3b1c43
4 files changed
+95 -3

No files matched your search

+25 -2
View File
@@ -45,6 +45,17 @@ class WebDAVStreamMixin:
async with client.put(url,data=data,headers={'If-None-Match':'*'}) as response:
if response.status not in (200,201,204):raise HTTPException(503,'WebDAV 分片重传失败,请重试')
async def _verify_stream_file(self, client, path, info, records):
# Cloud-backed reads can disconnect while the object is synchronizing.
# Retry only transport failures, retaining the assembled object.
for attempt in range(3):
try:
return await self._verify_offset_file(client, path, info, records)
except (aiohttp.ClientError, asyncio.TimeoutError) as exc:
if attempt == 2:
raise HTTPException(503, 'WebDAV 校验读取中断,已保留合并文件,请重试完成上传') from exc
await asyncio.sleep(attempt + 1)
async def finish_stream_upload(self, info, save_path):
records=await UploadChunk.filter(upload_id=info.upload_id,completed=True).order_by('chunk_index')
if [r.chunk_index for r in records]!=list(range(info.total_chunks)):raise ValueError('分片不完整')
@@ -52,8 +63,20 @@ class WebDAVStreamMixin:
staging=directory+'/assembled.bin'
async with aiohttp.ClientSession(auth=self.auth,timeout=OFFSET_TIMEOUT) as client:
# Recover a completed MOVE whose response/database acknowledgement was lost.
digest=await self._verify_offset_file(client,save_path,info,records)
digest=await self._verify_stream_file(client,save_path,info,records)
if digest is not None:return save_path,digest
try:
digest=await self._verify_stream_file(client,staging,info,records)
except ValueError:
# An interrupted PUT may leave a partial/corrupt staging object.
digest=None
if digest is not None:
move=asyncio.create_task(self._publish_offset(client,staging,save_path))
try:await asyncio.shield(move)
except asyncio.CancelledError:
await move
raise
return save_path,digest
async with client.delete(self._build_url(staging)) as response:
if response.status not in (200,204,404):raise HTTPException(503,'WebDAV 合并临时文件清理失败')
verified=0
@@ -82,7 +105,7 @@ class WebDAVStreamMixin:
await task
raise
if verified!=len(records):raise ValueError('分片校验未完成,请重新上传')
digest=await self._verify_offset_file(client,staging,info,records)
digest=await self._verify_stream_file(client,staging,info,records)
if digest is None:raise ValueError('合并后的文件不存在')
move=asyncio.create_task(self._publish_offset(client,staging,save_path))
try:await asyncio.shield(move)