Skip to content

posix: version restore overwrites the live file in place, and an aborted upload can roll back newer content #838

Open

Description

@Mortimer-RR

Description

Two related problems around restoring revisions on the posix driver:

  1. 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.
  2. 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:

  1. Upload version 1 and version 2 (1 GB, different content and mtimes) of a file.
  2. Download the file in a loop from several clients and restore versions meanwhile
    (COPY /remote.php/dav/meta/<fileid>/v/<version>).

Aborted older upload:

  1. File exists with content v0.
  2. Upload A over it; keep it in postprocessing (e.g. POSTPROCESSING_STEPS=delay).
  3. Upload B over it; let it finish.
  4. Abort A's postprocessing (opencloud storage-users uploads sessions --id <A> --clean).

Expected behavior

  • Every download during a restore returns exactly one version. A failed restore leaves the
    file untouched.
  • Aborting A leaves B's content in place.

Actual behavior

  • On upstream, all 50 downloads during the restores hashed to neither version. A copy that
    fails leaves a 0-byte file.
  • After aborting A, the file contains v0; B's content is gone.

Setup

OpenCloud a1982c6908 (reva 11d87fb6b985), posix driver, async postprocessing.
Go tests reproducing both are in the linked PR.

Activity

  1. pbleser-oc commented on Oct 16, 2026

    @pbleser-oc
    Member

    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:

    stream, _ := event.NewStream(defaults.FullDefaultConfig()) // services/storage-users/pkg/event
    _ = events.Publish(context.Background(), stream, events.PostprocessingFinished{
    	UploadID:  uploadID,
    	Outcome:   events.PostprocessingOutcome(outcome), // "continue" or "delete"
    	Timestamp: utils.TSNow(),
    })
    time.Sleep(3 * time.Second) // the nats client publishes asynchronously

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions