NextCloud File Lock Error in Joplin

I encountered a problem recently on the Joplin desktop app where it couldn’t synchronize due to a file lock being stuck in NextCloud. It uses a file in the jopline data directories to determine sync status and lock status on files being edited, and this file was stuck locked in NextCloud with no way to delete it. I performed some searching, finding some blog posts on the subject and found this on how to solve it. I’ll be going through the manual solution to this problem and updating the process with my experience.

Manually disable locking state:

  • Put Nextcloud in maintenance mode: edit config/config.php and change this line:
    'maintenance' => true,
    • Running NextCloud in docker, you’ll need to go to the path that you have mounted to /var/www/html in the container. For me this was in my NextCloud/html folder, so I went to NextCloud/html/config/config.php
Last Few Lines of Config.php Modified for maintenance mode
  • Empty table oc_file_locks: Use tools such as phpmyadmin or connect directly to your database and run (the default table prefix is oc_, this prefix can be different or even empty):
    DELETE FROM oc_file_locks WHERE 1
    • Running this from phpmyadmin, I saw that there would be 98k rows affected, this did make me nervous
  • disable maintenance mode (undo first step).
  • Make sure your cron-jobs run properly (you admin page tells you when cron ran the last time): https://docs.nextcloud.org/server/13/admin_manual/configuration_server/background_jobs_configuration.html 1.9k

Permanent solution (if it happens regularly)

  • on your own server: Use redis for this feature. It is faster and so far no problems have been reported. You can follow the instructions for memory-caching in the docs: https://docs.nextcloud.org/server/13/admin_manual/configuration_server/caching_configuration.html#id4 6.4k
  • Shared hosting (others who can’t install redis): You can disable the file locking, edit your configuration file config/config.php:
    'filelocking.enabled' => false,
    However, disabling is not a good solution. You can run into problems when several processes try to write to a file (especially online editors in the web-interface). In single-user and single-client environments, it’s probably less of a problem.

After running the manual method, everything worked properly, Joplin was able to synchronize and I saw no other side effects immediately afterwards. I’ll update this blog post if anything crops up. This only took 15 minutes, which I was nervous this maintenance would turn into a longer ordeal. I use Joplin for outlining and writing my blog posts away from my PC and then adding the content later to my blog or wiki depending on what it is. So keeping Joplin working was important to me.

Leave a Reply