Skip to content

PostWriteListener: LockedException during bulk upload via sync client #1617

@KrzysztofBond

Description

@KrzysztofBond

Describe the bug

During bulk file uploads via the Nextcloud desktop sync client, PostWriteListener fails with LockedException because the file has an exclusive lock from the upload process, and TimelineWrite::processFile() tries to acquire another exclusive lock.

This results in "Write hook failed to index file" errors for every image uploaded during concurrent sync operations. The files are never indexed in real-time.

Environment

  • Memories: 7.8.2
  • Nextcloud: 32.0.5
  • PHP: 8.x
  • DB: MariaDB 11.8
  • Sync client: 4.0.6

Steps To Reproduce

Root cause
In TimelineWrite.php:55-67, processFile() acquires LOCK_EXCLUSIVE by default. But during a DAV PUT (upload), the file already has an exclusive lock from Nextcloud core. The lock conflict causes an unhandled LockedException.

Proposed fix - proposal contributed by arkDisk

Catch LockedException in PostWriteListener.php and log at debug level. The file will be picked up by the background cron indexer:

} catch (LockedException $e) {
    $this->logger->debug('File locked during upload, deferring to cron', [
        'app' => 'memories',
        'path' => $node->getPath(),
    ]);
} catch (\Exception $e) {

This is a one-line fix that preserves real-time indexing for single uploads while gracefully handling bulk uploads.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions