Skip to content

posix: an overwriting upload can deadlock on its own node lock after a metadata cache miss #1006

Description

@pbleser-oc

On posix, an upload that overwrites an existing file can wait forever for the metadata lock that it already holds itself. The file then stays locked: later uploads to it hang as well, the postprocessing workers block behind it, and the file stays in processing (HTTP 425) until the service is restarted.

It only happens when the node's metadata is missing from the cache at the wrong moment. decomposed and decomposeds3 are not affected.

Where

pkg/storage/pkg/decomposedfs/prepare_upload.go, PrepareUpload, when the node exists (as of 3acb80d):

  • line 161: fs.lu.MetadataBackend().Lock(n)
  • line 211: node.ReadNode(ctx, fs.lu, n.SpaceID, n.ID, ...), which reads the same node through a new node object

Why it blocks

Lock(n) marks only the object n as holding the lock. node.ReadNode creates a new object for the same node, which doesn't know that the lock is held. When the metadata isn't cached, HybridBackend.All reads it from disk under the lock and takes the lock again, through a second file descriptor. flock on a second file descriptor blocks even within the same process, so the upload waits for its own lock.

The cache usually hides this, because the node was read just before. It takes a cache miss in between, e.g. an eviction, or metadata written by another process such as opencloud posixfs scan. The messagepack backend of decomposed and decomposeds3 reads without taking the lock, so it doesn't block there.

How to reproduce

  • At the backend level: lock a node through one node object, write an attribute directly to the file so that it isn't cached, then call All through a second object for the same path. It never returns. The same call with the metadata cached returns at once. I can add this as a test.
  • Through the upload path: TestUploadWithColdMetadataCache in fix(posix): stale metadata cache after 'opencloud posixfs scan' #962 expires the cache entry while overwrites run, and fails without its fix.
  • Under load: before the rework of the upload path, concurrent uploads, moves and deletes on a few files, plus opencloud posixfs scan in a loop, left goroutines stuck in flock for minutes after the load had stopped. The same test on 3acb80d (300 s, 32 clients, with and without watch_fs) left none, so the current code hits it less often under this load.

Fix

#962 fixes it in PrepareUpload: it reads the existing node with node.LockAndReadNode and keeps that lock, instead of Lock plus ReadNode.

A broader fix would make the backend lock re-entrant per file within the process, by tracking the held lock files by path instead of a flag per node object. That would remove this class of problem for every caller that locks a node and then reads it through another object.

AI assistance: Claude Code (claude-opus-5-5) found the cause, wrote the reproducer and the first draft of this issue.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions