[Bug]: Late failed chunk PUT deletes a successful retry, causing final MOVE 400
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start with apps/dav/lib/Upload/UploadFolder.php, especially UploadFolder::createFile() and its exception cleanup, then inspect the storage behavior of File::put() and related upload tests. Reproduce the interleaving described in the issue and add a regression test showing that a failed PUT leaves a successful same-name retry available for assembly. Done means the regression passes while cleanup still handles partial data across storage implementations.
由索引模型根据 Issue 内容生成。
描述
Summary
A late failure in OCA\DAV\Upload\UploadFolder::createFile() can delete the final chunk already committed by another request retrying the same chunk name.
The retry returns 201 Created. When the original incomplete request eventually fails, its catch block looks up the chunk by name and deletes it. The final MOVE .../.file then returns 400 Bad Request because the stored chunks no longer add up to OC-Total-Length.
Verification scope
- Reproduced with real WebDAV requests on a downstream image based on official
nextcloud:34.0.2-apache. - Reproduced directly against Apache, without Traefik in the request path.
- A follow-up test sent the successful retry, final MOVE, and content download through Traefik HTTPS. The original incomplete request was sent directly to Apache to control its failure timing.
- Inspected official
v34.0.5,v35.0.2,v34.0.6rc1,v35.0.3rc1, and currentmasteron 2026-11-08. They retain this cleanup logic. - A focused PHP regression harness loading the unmodified
UploadFolder.phpfrom bothv34.0.5andv35.0.2also fails with “Late failure deleted the successful retry”. This harness simulates the interleaving using a Directory test double. - A complete deployment of the latest patch releases has not been tested. The live instance also includes an unrelated downstream
Directory::createFile()change to release upload locks in a finally block. Please distinguish the live reproduction from the focused newer-source regression tests.
Steps to reproduce
Use a disposable test account and an HTTP Apache upstream accessible from the test machine. Configure the origin as a trusted Nextcloud URL. No reverse proxy is required.
- Create a unique authenticated DAV upload collection.
- Start PUT A to chunk
1, declaring a 2 MiB Content-Length but initially sending only 8 KiB. Keep the connection open. - Send PUT B to the same chunk URL with a complete 2 MiB payload. Observe
201 Created. - End PUT A's request body early. Observe
400 Bad Request. - Send
MOVE <upload>/.filewithOC-Total-Length: 2097152and a Destination header.
Minimal Python 3 reproduction, using only the standard library. Set NC_URL to the local HTTP origin, for example http://localhost:8080, and NC_USER to a disposable test account. The password is prompted without echo. Only the uniquely named synthetic paths are cleaned up.
import base64
import getpass
import http.client
import os
import secrets
import socket
import time
from urllib.parse import quote, urlsplit
origin = os.environ["NC_URL"].rstrip("/")
url = urlsplit(origin)
assert url.scheme == "http", "Use the direct local Apache HTTP upstream"
user = quote(os.environ["NC_USER"], safe="")
password = getpass.getpass("Test account password/app password: ")
auth = "Basic " + base64.b64encode(
(os.environ["NC_USER"] + ":" + password).encode()
).decode()
session = "retry-repro-" + secrets.token_hex(8)
upload = url.path.rstrip("/") + "/remote.php/dav/uploads/" + user + "/" + session
target = url.path.rstrip("/") + "/remote.php/dav/files/" + user + "/" + session + ".bin"
destination = url.scheme + "://" + url.netloc + target
data = b"B" * (2 * 1024 * 1024)
def request(method, path, body=None, extra=None):
conn = http.client.HTTPConnection(url.hostname, url.port or 80, timeout=40)
headers = {
"Host": url.netloc,
"Authorization": auth,
"X-Requested-With": "XMLHttpRequest",
}
headers.update(extra or {})
conn.request(method, path, body=body, headers=headers)
response = conn.getresponse()
result = response.status, response.read()
conn.close()
return result
original = None
try:
status, body = request("MKCOL", upload, extra={
"Destination": destination, "Content-Length": "0",
})
assert status == 201, (status, body)
original = socket.create_connection((url.hostname, url.port or 80), timeout=40)
headers = (
f"PUT {upload}/1 HTTP/1.1\r\n"
f"Host: {url.netloc}\r\nAuthorization: {auth}\r\n"
f"Content-Length: {len(data)}\r\nConnection: close\r\n\r\n"
)
original.sendall(headers.encode() + b"A" * 8192)
time.sleep(1)
print("Complete retry:", request("PUT", upload + "/1", data)[0])
original.shutdown(socket.SHUT_WR)
reply = b""
while True:
block = original.recv(65536)
if not block:
break
reply += block
print("Original incomplete PUT:", reply.split(b"\r\n", 1)[0].decode())
print("Assembly:", request("MOVE", upload + "/.file", extra={
"Destination": destination, "OC-Total-Length": str(len(data)),
}))
finally:
if original is not None:
original.close()
request("DELETE", upload)
request("DELETE", target)
Actual behavior
Observed before changing UploadFolder cleanup, with a 2 MiB synthetic payload
Complete retry: 201
Original incomplete PUT: HTTP/1.1 400 Bad Request
Assembly: 400
Sabre\DAV\Exception\BadRequest
Chunks on server do not sum up to 2097152 but to 0 bytes
In a browser large-file upload we also observed successful chunk retries followed several minutes later by failures of the older PUTs, and finally MOVE 400.
Expected behavior
Failure cleanup must only remove data belonging to the failed attempt. A chunk already committed by a successful retry must remain available for final assembly.
Relevant implementation and local experiment
UploadFolder::createFile() catches the exception from the underlying Directory and, if a child with the requested name exists, deletes that child without establishing that the child belongs to the failed attempt. File::put() already manages per-attempt partial-file cleanup on the local storage path used here.
Removing that outer name-based deletion while allowing the original exception to propagate changed the same real HTTP test to
Complete retry: 201
Original incomplete PUT: HTTP/1.1 400 Bad Request
Assembly: 201
Download: 2097152 bytes, exactly matching the complete retry payload
SHA-256: 7995dfceebfb9fa8972d361d53d899f6e268ecd6d823b5737198041fabc02e20
This local experiment establishes the cleanup race on our storage path. Any upstream fix should also account for storage implementations with different partial-file behavior.
The affected method is present in these official sources.
Environment
- Live server version tested: 34.0.2, Apache-based downstream Docker image
- PHP: 8.5.9
- OS inside container: Debian GNU/Linux 13
- Database configuration: PostgreSQL (
dbtype=pgsql) - File locking: enabled, Redis
- Primary data: local filesystem exposed through a bind mount
- Server-side encryption: disabled
- Browser reproduction: Chrome, authenticated upload
- Upload settings during the affected browser test: 16 MiB chunks, maximum parallel count 2
- Existing recovery administrator used for the successful synthetic HTTP test. A separate temporary ordinary-user probe timed out during initial setup and is not counted as a successful reproduction.
- Full configuration, credentials, private hostnames, user identifiers, and user files are intentionally omitted.
Related reports searched
#65408 concerns public-share final assembly being interrupted and the web uploader deleting the session. #63071 concerns interrupted assembly and destination/filecache inconsistency. This report isolates an earlier server-side chunk PUT failure deleting a successful same-name retry before assembly.
Additional information
AI assistance was used to investigate the source, organize the reproduction, run the controlled tests, and draft this report. The HTTP results and before/after content comparison were observed on the affected instance. Newer releases were checked using source inspection and a focused regression harness as described above.
- 主要语言
- PHP
- 星标
- 37.5k
- 派生
- 5.4k
- 平均合并
- 1 天 13 小时
- 30 天内合并 PR
- 639
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
nextcloud/server 的其他 Issue
-
35-feedback
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
0. Needs triage 35-feedback bug
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 1 天内回复
-
workflowengine: File entity reuses the node of the first "Tag assigned" event for all later events in the same process可能已有人在做 @lazerg 于 2 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
Contacts import aborts with TypeError when vCards have no UID (TextImporter structure)可能已有人在做 @SebastianKrupinski 于 6 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 72/100
nextcloud/server#66486 · 2 条评论 · 2 个 reaction · 已指派 1 人 ·
维护者通常 1 天内回复
-
Unified search: screen reader hears "No matching results" on mobile even when there are results可能已有人在做 @lazerg 于 10 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
相似的 Issue
-
[Sync EN] stream: document the errors of the stream_context_*() and stream filter functions (#6091)未关闭sync-en
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
-
难度 2/5 1-3 小时 新手友好度 79/100
Automattic/blocks-engine#6318 ·
维护者通常 1 天内回复
-
Update: Laravel Cheat Sheet - middleware examples for the bootstrap/app.php layout (small update)未关闭
难度 2/5 1-3 小时 新手友好度 84/100
OWASP/CheatSheetSeries#2990 ·
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复