File is locked - how to unlock


#21

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 ?


#22

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: : https://docs.nextcloud.com/server/13/admin_manual/configuration_files/files_locking_transactional.html


#23

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?


#24

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?


#25

Instructions is in the first post :wink:


#26

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


#27

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


#28

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!


#29

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


#30

This works for me


#31

@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?


#32

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.


#33

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.


#34

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…


#35

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!


#36

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


#37

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.


#38

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


#39

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.


#40

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