Skip to content

pkg/storage: release quota of orphaned upload sessions - #692

Merged
mklos-kw merged 1 commit into
owncloud:mainfrom
kobergj:fix/ocisdev-1177-orphaned-upload-sessions
Aug 6, 2026
Merged

mklos-kw merged 1 commit into
owncloud:mainfrom
kobergj:fix/ocisdev-1177-orphaned-upload-sessions

Conversation

@kobergj

@kobergj kobergj commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Problem

When an upload's target node loses its metadata — for example because an ancestor directory is moved to the trash while the upload is still in flight — the node file stays on disk without a readable .mpk. Reading such a node fails with internal error: Missing parent ID on node, so the upload can never finish postprocessing:

  • it stays in Processing forever
  • it cannot be downloaded (HTTP 425) or deleted
  • it keeps consuming the space quota

The error surfaces at node/node.go:398. It is reachable because loadAttributes returns empty attributes rather than ENOENT when the .mpk is gone but the node file remains, so the node reports Exists = true with every attribute blank and ParentID == "" is simply the first field checked.

Cleaning these sessions up did not work either, and made things worse:

  1. Cleanup removed the upload bytes and the session .info file first, then attempted to revert the node and bailed out on the failing read — never reaching the quota release.
  2. That destroyed both the only copy of the uploaded data (the blob was never written, so uploads/<id> is all there is) and the NodeParentId recorded in the .info file, which is the only remaining information needed to repair the node.
  3. PostprocessingFinished returned early on the unreadable node before Cleanup was called at all, leaving the session behind to be retried indefinitely.

Net effect: running a cleanup on an affected session converted a recoverable state into unrecoverable data loss while freeing nothing.

Changes

  • Revert before deleting. Cleanup now reverts the node before removing the bin and info files, so a failure leaves a recoverable session instead of a deleted one.
  • Fall back to the session metadata. When the node cannot be read, the quota is released by propagating the negative size diff from a node built out of the session's own SpaceID/NodeID/NodeParentID, and the orphaned node file plus its metadata are removed. Propagation only needs the parent id, which the session still has.
  • Keep the upload if the quota cannot be released, so it can be retried rather than lost.
  • Handle orphaned sessions on PostprocessingFinished instead of returning early and leaving them to be retried forever.
  • New Orphaned upload session filter to list affected sessions. It is only evaluated when set, since it reads the node metadata of every session — default listings are unchanged.

Behaviour for readable nodes is unchanged.

Tests

Adds a regression test covering an upload whose node metadata has become unreadable: it asserts the orphaned node is removed, the bytes are cleaned up, and — the actual point — that the quota is released.

The test purges the metadata through the backend rather than unlinking the .mpk directly, otherwise the cached attributes keep the node readable and the test passes even without the fix. Verified that it fails without these changes and passes with them.

Notes

make lint could not be run locally: the pinned golangci-lint (v1.61.0, built with Go 1.23) refuses the repository's Go 1.26 target. This is pre-existing and unrelated to this change; gofmt and go vet are clean.

🤖 Generated with Claude Code

@kobergj
kobergj requested a review from a team as a code owner August 6, 2026 07:41
When an upload's target node lost its metadata, e.g. because an ancestor was
trashed while the upload was in flight, the node file remained without a
readable .mpk. Reading it fails with "Missing parent ID on node", so the upload
never finished postprocessing: it stayed in "Processing", could not be
downloaded or deleted, and kept consuming the quota.

Cleanup made this worse. It removed the upload bytes and the session info file
before attempting to revert the node, then bailed out on the failing node read
without releasing the quota - destroying both the only copy of the data and the
parent id needed to repair the node, while freeing nothing.

Revert the node before anything irreversible and fall back to the parent id
recorded in the session when the node cannot be read, so the quota is released
and the orphaned node removed. Keep the upload if the quota cannot be released.
Also clean up such sessions when postprocessing finishes instead of returning
early and leaving them to be retried forever.

Add an Orphaned upload session filter to list affected sessions. It is only
evaluated when set, as it reads the node metadata of every session.

Signed-off-by: Julian Koberg <[email protected]>
@kw-security

kw-security commented Aug 6, 2026 •

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues
✅ Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@kobergj
kobergj force-pushed the fix/ocisdev-1177-orphaned-upload-sessions branch from fe3d6f3 to 841de45 Compare August 6, 2026 07:41
@mklos-kw
mklos-kw merged commit 831afd0 into owncloud:main Aug 6, 2026
16 checks passed
mklos-kw added a commit that referenced this pull request Sep 10, 2026
When an upload's target node lost its metadata, e.g. because an ancestor was
trashed while the upload was in flight, the node file remained without a
readable .mpk. Reading it fails with "Missing parent ID on node", so the upload
never finished postprocessing: it stayed in "Processing", could not be
downloaded or deleted, and kept consuming the quota.

Cleanup made this worse. It removed the upload bytes and the session info file
before attempting to revert the node, then bailed out on the failing node read
without releasing the quota - destroying both the only copy of the data and the
parent id needed to repair the node, while freeing nothing.

Revert the node before anything irreversible and fall back to the parent id
recorded in the session when the node cannot be read, so the quota is released
and the orphaned node removed. Keep the upload if the quota cannot be released.
Also clean up such sessions when postprocessing finishes instead of returning
early and leaving them to be retried forever.

Add an Orphaned upload session filter to list affected sessions. It is only
evaluated when set, as it reads the node metadata of every session.

Signed-off-by: Julian Koberg <[email protected]>
Co-authored-by: kobergj <[email protected]>
butonic added a commit to butonic/reva that referenced this pull request Oct 29, 2026
Port of owncloud#692, adapted to our diverged decomposedfs copies:

- Add an Orphaned upload session filter to storage.UploadSessionFilter,
  evaluated last in ListUploadSessions of both copies because it reads
  the node metadata of every session.
- Add IsOrphaned and syntheticNode to OcisSession and DecomposedFsSession.
- Extract the node reverting from upload.Cleanup into revertNode and run
  it before the bin and info files are removed, so a failure leaves a
  recoverable session instead of a deleted one. The readable-node branch
  keeps our local RevertUpload/Purge logic (upstream has
  RevertCurrentRevision). When the node metadata is unreadable, revert
  the optimistic size propagation from a node built out of the session's
  SpaceID/NodeID/NodeParentID and remove the orphaned node, so the space
  quota is released; the upload is kept when the quota cannot be
  released. In the pkg fork the orphaned node is removed via lu.PurgeNode
  and its metadata via the MetadataNode-based backend Purge.
- Clean up orphaned sessions on PostprocessingFinished instead of
  returning early and leaving them to be retried forever.
- Add the regression test to both upload_async_test.go copies.

Changelog is maintained in the ready-release-go PR, not per commit.

Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
dragonchaser pushed a commit to dragonchaser/reva that referenced this pull request Nov 4, 2026
Port of owncloud#692, adapted to our diverged decomposedfs copies:

- Add an Orphaned upload session filter to storage.UploadSessionFilter,
  evaluated last in ListUploadSessions of both copies because it reads
  the node metadata of every session.
- Add IsOrphaned and syntheticNode to OcisSession and DecomposedFsSession.
- Extract the node reverting from upload.Cleanup into revertNode and run
  it before the bin and info files are removed, so a failure leaves a
  recoverable session instead of a deleted one. The readable-node branch
  keeps our local RevertUpload/Purge logic (upstream has
  RevertCurrentRevision). When the node metadata is unreadable, revert
  the optimistic size propagation from a node built out of the session's
  SpaceID/NodeID/NodeParentID and remove the orphaned node, so the space
  quota is released; the upload is kept when the quota cannot be
  released. In the pkg fork the orphaned node is removed via lu.PurgeNode
  and its metadata via the MetadataNode-based backend Purge.
- Clean up orphaned sessions on PostprocessingFinished instead of
  returning early and leaving them to be retried forever.
- Add the regression test to both upload_async_test.go copies.

Changelog is maintained in the ready-release-go PR, not per commit.

Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants