You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
posix: version restore overwrites the live file in place, and an aborted upload can roll back newer content #838
Two related problems around restoring revisions on the posix driver:
pkg/storage/fs/posix/tree/revisions.go, RestoreRevision, opens the target, Truncate(0)s it and io.Copys the revision into it. No temp file, no rename, no fsync.
Readers can see an empty or partially restored file. If the copy fails, the function
returns before CopyMetadata, leaving a truncated file whose xattrs still describe the
previous content.
pkg/storage/pkg/decomposedfs/upload/upload.go, Cleanup: when revertNodeMetadata
is true and the session has a versionID, it calls RestoreRevision without the node
lock and without checking that the session still owns the node. Unlike the else branch
below it, it doesn't compare ProcessingID. If postprocessing of an older upload fails
after a newer upload has finished, the newer content is replaced by the version from
before the older upload.
Steps to reproduce
Restore under load:
Upload version 1 and version 2 (1 GB, different content and mtimes) of a file.
Download the file in a loop from several clients and restore versions meanwhile
(COPY /remote.php/dav/meta/<fileid>/v/<version>).
Aborted older upload:
File exists with content v0.
Upload A over it; keep it in postprocessing (e.g. POSTPROCESSING_STEPS=delay).
I ran into the second problem independently, while analysing how the revision cleanup of opencloud-eu/opencloud#1419 deals with overlapping uploads, and can confirm it for both posix and decomposed, on reva main (8ee5e6d16) with OpenCloud 40095460a1. (Strictly speaking with the branch of opencloud-eu/opencloud#1419 on top, with its revision cleanup disabled; it doesn't change the upload code involved here.) A few things in addition to the description above:
On current main, posix ends up corrupted, not rolled back
The description above matches the code it was tested with (11d87fb6b), where Cleanup rolled back with RestoreRevision. A few hours after this issue was opened, #821 was merged, and Cleanup now uses Node.RevertUpload instead, which only copies the version's metadata onto the file, no bytes. With posix, the file's bytes are the newer upload's at that point, so the file is left with B's bytes and the metadata of the content from before A:
after A failed
decomposed
posix
download of the file
v0 (B's blob is orphaned)
B's content, cut to the size of v0
size and checksum reported
v0's
v0's
modification time reported
v0's
B's
bytes on disk
– (blobs)
B's
xattrs on disk
–
v0's blob id, size, checksums and user.oc.mtime
With v0 = C0-original (11 bytes), A = CA-the-older-upload (19 bytes) and B = CB-the-newer-upload-B (21 bytes), a download after A's failure returned C0-original with decomposed, and CB-the-newe with posix.
The modification time is B's with posix because posix reports the file system's mtime (timemanager.MTime uses os.Stat); the user.oc.mtime xattr that RevertUpload copies back is only written along with it, never read for that.
The version meant for the older upload is left behind, broken
When B's bytes are received while A is still in postprocessing, updateExistingNode creates a version for A's content (named after A's mtime), into which A's Finalize writes A's bytes if A succeeds later. When A fails instead, that version stays, and it's broken:
decomposed: it points to A's blob, which was never written; downloading it fails with HTTP 500;
posix: Tree.CreateRevision copied the file's bytes at that moment, which were still v0 (A hadn't succeeded yet), so the version contains v0's bytes under A's metadata (blob id, size 19, A's checksum).
This is the known FIXME in Cleanup ("else if the upload has become a revision, delete the revision, or if it is the last one, delete the node") and in upload_async_test.go ("FIXME we need to delete the revision"). I tested #839 merged onto current main: it keeps B's content with both drivers, but it keeps this version as well ("leaves the revision as an ordinary version"), so it stays broken: with decomposed, downloading it still fails with HTTP 500. I'll open a separate issue and PR on top of #839 for that.
Other orders go wrong as well
The same roll back is also wrong when both uploads fail: the newer upload rolls back to the version recorded in its session, which is the version created for the older upload, whose content was never written. On main, that happens when the older upload fails first (when the newer one fails first, the older upload's own roll back repairs it afterwards); with #839, it happens in both orders, as the older upload no longer rolls back once it doesn't own the node. The outcomes of all orders, on main and with #839, are in my review of #839.
On disk, with posix, step by step
REV.<time> stands for the version files in .oc-nodes of the space, named after the mtime of the content they keep; t0, tA and tB are the mtimes of v0, A and B.
1. the file exists
report.txt bytes: v0 xattrs: v0's blob id, size, checksums
2. A's bytes received (A's bytes wait in uploads/ until its postprocessing succeeds)
REV.t0 (new copy) bytes: v0 xattrs: v0's
report.txt bytes: v0 xattrs: A's, status processing:<A>
3. B's bytes received (B's bytes wait in uploads/)
REV.tA (new copy) bytes: v0 xattrs: A's <-- A would write its bytes in here
report.txt bytes: v0 xattrs: B's, status processing:<B>
B succeeds
report.txt bytes: B xattrs: B's <-- consistent
4. A fails: Cleanup -> RevertUpload(REV.t0): copies REV.t0's xattrs onto report.txt, deletes REV.t0
report.txt bytes: B xattrs: v0's <-- don't match
REV.t0 deleted
REV.tA bytes: v0 xattrs: A's <-- don't match, left behind
How I reproduced it
With an OpenCloud server, holding every upload in postprocessing with POSTPROCESSING_DELAY=1h, and publishing the PostprocessingFinished events myself in the order needed (B continue, then A delete), with a small helper built within the opencloud module:
The upload ids come from opencloud storage-users uploads sessions --processing --json. That makes the order of the outcomes deterministic, and works for any driver.
Activity
pbleser-oc commentedon Oct 16, 2026
I ran into the second problem independently, while analysing how the revision cleanup of opencloud-eu/opencloud#1419 deals with overlapping uploads, and can confirm it for both posix and decomposed, on reva
main(8ee5e6d16) with OpenCloud40095460a1. (Strictly speaking with the branch of opencloud-eu/opencloud#1419 on top, with its revision cleanup disabled; it doesn't change the upload code involved here.) A few things in addition to the description above:On current
main, posix ends up corrupted, not rolled backThe description above matches the code it was tested with (
11d87fb6b), whereCleanuprolled back withRestoreRevision. A few hours after this issue was opened, #821 was merged, andCleanupnow usesNode.RevertUploadinstead, which only copies the version's metadata onto the file, no bytes. With posix, the file's bytes are the newer upload's at that point, so the file is left with B's bytes and the metadata of the content from before A:v0(B's blob is orphaned)v0v0'sv0'sv0'sv0's blob id, size, checksums anduser.oc.mtimeWith
v0=C0-original(11 bytes), A =CA-the-older-upload(19 bytes) and B =CB-the-newer-upload-B(21 bytes), a download after A's failure returnedC0-originalwith decomposed, andCB-the-newewith posix.The modification time is B's with posix because posix reports the file system's mtime (
timemanager.MTimeusesos.Stat); theuser.oc.mtimexattr thatRevertUploadcopies back is only written along with it, never read for that.The version meant for the older upload is left behind, broken
When B's bytes are received while A is still in postprocessing,
updateExistingNodecreates a version for A's content (named after A's mtime), into which A'sFinalizewrites A's bytes if A succeeds later. When A fails instead, that version stays, and it's broken:Tree.CreateRevisioncopied the file's bytes at that moment, which were stillv0(A hadn't succeeded yet), so the version containsv0's bytes under A's metadata (blob id, size 19, A's checksum).This is the known
FIXMEinCleanup("else if the upload has become a revision, delete the revision, or if it is the last one, delete the node") and inupload_async_test.go("FIXME we need to delete the revision"). I tested #839 merged onto currentmain: it keeps B's content with both drivers, but it keeps this version as well ("leaves the revision as an ordinary version"), so it stays broken: with decomposed, downloading it still fails with HTTP 500. I'll open a separate issue and PR on top of #839 for that.Other orders go wrong as well
The same roll back is also wrong when both uploads fail: the newer upload rolls back to the version recorded in its session, which is the version created for the older upload, whose content was never written. On
main, that happens when the older upload fails first (when the newer one fails first, the older upload's own roll back repairs it afterwards); with #839, it happens in both orders, as the older upload no longer rolls back once it doesn't own the node. The outcomes of all orders, onmainand with #839, are in my review of #839.On disk, with posix, step by step
REV.<time>stands for the version files in.oc-nodesof the space, named after the mtime of the content they keep;t0,tAandtBare the mtimes ofv0, A and B.How I reproduced it
With an OpenCloud server, holding every upload in postprocessing with
POSTPROCESSING_DELAY=1h, and publishing thePostprocessingFinishedevents myself in the order needed (Bcontinue, then Adelete), with a small helper built within the opencloud module:The upload ids come from
opencloud storage-users uploads sessions --processing --json. That makes the order of the outcomes deterministic, and works for any driver.Related