File is locked - how to unlock

Thank you for your answer.

I would also like to have some confirmationā€¦ likeā€¦ is it normal to have 40.000 locks in a database?
Is my locking system working good? I have around 100.000 files.

I also have 5 main directories owned by a ā€œadminā€ owner and shared with the others, so everyone uploads files in that directories.
I made this choice so that the ā€œadminā€ user still owns the files if someone go rogue.

Is this the reason why I have 50% of files locked ?

If you have that many locks in your database you have a serious problem. Use Redis for transactional file locking as said in the first post by @tflidd.

If they are stored in your database you donā€™t use transactional locking as described here: : Transactional file locking ā€” Nextcloud 13 Administration Manual 13 documentation

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:

1 Like

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

4 Likes

This works for me

1 Like

@tflidd, your 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?

2 Likes

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).