File is locked - how to unlock

I get the same error message when doing a “occ files:scan” for a specific user. The error starts with:

Exception during scan: File entry could not be inserted with insertIfNotExist() but could also not be selected with getId() in order to perform an update. Please try again.

Then 21 lines with more specific errors. What´s wrong here? How can I perform a “file system vs. database nc_filecache” comparison?

I get that same error too for one of my users, tried to do occ files:cleanup but it did not help (0 orphaned file cache entries deleted)
How do we go about this issue?

Instructions is in the first post :wink:

Yes of course, and I already did manually disable the locking state beforehand. I had this a while ago already, that’s where I started using redis, but the problem seems to persist
MariaDB says: Query OK, 0 rows affected (0.01 sec)
fsck.ext4 says that everything is fine

Report it on github, seems this is a bug :wink:

crazy, and nextcloud even seems to show files on the web-ui that are not there on the disk - even after a occ files:scan --all
…ok, I guess I’ll report it. Thanks though!

Hi amo13

I had the same Problems a few times. But I could always fix it with this procedure (retain the order!):

  • occ ‘files:scan --all’
  • occ ‘files:cleanup’
  • occ ‘maintenance:mode --on’
  • mysql -u root -p’inheregoesyourpassword’ -D ocdb -e ‘delete from oc_file_locks where 1’
  • occ ‘maintenance:mode --off’
  • restart your Nextcloud webserver and try again -> the files in your web-ui should be gone.

Good Luck, Cheers zisuu

3 Likes

This works for me

@tflidd, yout manual does not work for me on Ubuntu 16.04.1 server x64 with Nextcloud 13.0.2

Yes, i found FileLocked in nextcloud.log.

Yes, i have redis and apcu installed

config.php:

  'memcache.distributed' => '\\OC\\Memcache\\Redis',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'redis' => array (
              'host' => 'localhost',
              'port' => 6379,
            ),

Yes, i have emptied the table oc_file_locks

‘maintenance’ => true,
DELETE FROM oc_file_locks WHERE 1
‘maintenance’ => false,

Yes, i executed the cron job manually after disabling maintainance mode without any errors

sudo -u www-data php -f /var/www/nextcloud/cron.php

Nevertheless those files are still locked and oc_file_locks is empty.

Can you please explain that behavior or what is to do?

Thank you!

BTW: Why don’t add an admin option in the GUI for deleting the file lock?

1 Like

Give your services/server a bounce (restart). May just be a locked process or something untoward.

The steps outlined by @tflidd will manually force any file locks to be removed by dropping them from the database forcibly. This should normally be taken care of by the system but as is clearly demonstrated throughout the thread it isn’t foolproof.

Sorry i forgot to mention that i did a restart of redis and apache already:

service redis restart
service apache2 restart

But this did not unlock the files.

Bounce the server. Could it be they’re locked by something else? Another process on the server accessing the file for some reason or something…

I don’t think so because i’m the only user of the server. It’s hosted on localhost in a virtual machine.

Meanwhile i could remove the file lock by setting

'filelocking.enabled' => false,

temporarely, with the success that the Windows desktop sync client can’t sync the folder in question anymore.

Strange!

Provide full screenshot to see the ending of the file :wink: then we might help you more :wink:

It’s a directory with 2 PDF files inside.

It is the directory which was locked before.

The ignored file list of the desktop sync client does not contain any pdf files and i did not alter it.

A post was split to a new topic: Many files are locked during scan of user folder

Did you try to delete the keys in the redis database ?
On Centos with a socket connection :

sudo redis-cli -s /var/run/redis/redis.sock flushall

It’s quite radical, but works for me.

Thank you! This worked for me. By the way, I’m running Nextcloud in an iocage jail on FreeNAS, so I changed www-data to www
By the way, your config.php file has to be in ordinary mode (not maintenance mode).

For anyone having issues with files getting lock while using redis on nextcloud pi. Specially while syncing nodejs apps…

  1. Connect to your redis
    sudo redis-cli -s /var/run/redis/redis.sock
  2. authenticate in your redis with the password for redis found in /var/www/nextcloud/config/config.php
    $> auth “yourpasswordfoundinconfig.php”
    $> flushall
    Your locked files should synchronize now
3 Likes

This error/bug has been driving me crazy. Because there was so much variety in the user posts, I created a more standardized testing environment and replicated the bug with a standardized dataset on clean new installs using both postgres & mysql. In the process I created a one-run install script that requires minimal configuration/expertise to use. Doing the file/redis maintenance options are not actually solutions if the bug is evident on clean installs (they merely temporize the issue). Any recommendations on where to look (e.g. in nextcloud codebase) to get this bug fixed would be appreciated!

I want to see nextcloud succeed, and for it to do so this issue needs fixing!

Install script/writeup: https://gitlab.com/deepthought/nextcloud-docker/tree/latest
For freenas users (script not as good, worse deadlock errors): https://github.com/ak1n/freenas-iocage-nextcloud

1 Like