[Bug]: Late failed chunk PUT deletes a successful retry, causing final MOVE 400
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 45/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- PHP
- Estrellas
- 37.5k
- Forks
- 5.4k
- Merge medio
- 1 d 13 h
- PR fusionados (30 d)
- 639
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de nextcloud/server
-
35-feedback
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
0. Needs triage 35-feedback bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
Los mantenedores suelen responder en 1 día
-
workflowengine: File entity reuses the node of the first "Tag assigned" event for all later events in the same processPosiblemente ocupada @lazerg la tomó hace 2 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día
-
Contacts import aborts with TypeError when vCards have no UID (TextImporter structure)Posiblemente ocupada @SebastianKrupinski la tomó hace 6 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
nextcloud/server#66486 · 2 comentarios · 2 reacciones · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Unified search: screen reader hears "No matching results" on mobile even when there are resultsPosiblemente ocupada @lazerg la tomó hace 10 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
Todos los issues de nextcloud/server
Issues similares
-
[Sync EN] stream: document the errors of the stream_context_*() and stream filter functions (#6091)Abiertosync-en
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 79/100
Automattic/blocks-engine#6318 ·
Los mantenedores suelen responder en 1 día
-
Update: Laravel Cheat Sheet - middleware examples for the bootstrap/app.php layout (small update)Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
OWASP/CheatSheetSeries#2990 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día