Files locks not releasing

Nextcloud version: 18.02
Operating system and version: SME Server 9.02
Apache or nginx version: Apache/2.2.15
PHP version: 7.3

The issue you are facing:

File locks do not appear to be releasing. Several files have multiple locks on them, as many as 9 or 10 according to the oc_file_locks table. We have a process that creates files which are then synched with NextCloud so others can use them. These are library files for an application called Omnis; in short, they are pieces used to build an application. Because of the file locks, the NextCloud files are not getting automatically updated the way they should be.

Is this the first time you’ve seen this error?

Yes and No. We had this problem under NC 16, but we disabled filelocking. We recently re-enabled filelocking under 18.03 (and after that updated to 18.04). Everything worked at first, but on 5/15 the file locking started preventing our builds from updating.

Steps to replicate it:

  1. Our build process runs, creates several files
  2. Those files are placed in a directory which synchs with NextCloud
  3. Synch fails for some of the files. In the NextCloud client, under Activity, we get a message: Server replied “423 Locked” to “PUT URI/filename”

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!): (Some lines are removed as they are “identifiable information”)

$CONFIG = array (
  'datadirectory' => '/home/e-smith/files/ibays/nextcloud/html/data',
  'dbtype' => 'pgsql',
  'version' => '18.0.4.2',
  'dbname' => 'nextcloud',
  'dbtableprefix' => 'oc_',
  'installed' => true,
  'filelocking.enabled' => true,
  'mail_from_address' => 'nextcloud',
  'mail_smtpmode' => 'smtp',
  'mail_smtpauthtype' => 'LOGIN',
  'maintenance' => false,
  'theme' => '',
  'loglevel' => 2,
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'updater.release.channel' => 'stable',
);

The output of your Apache/nginx/system log in /var/log/____:
Nothing related to this problem is in the log file. The problem occurred this morning, and the last entry in the system log file is from several hours before the failure.

Can you install a redis cache? This handles file locks much faster and there are less problems reported.

I have now installed Redis and configured for it. I will let you know if this helps. :slight_smile:

Redis does not seem to be helping. I am not confident it is properly configured. When I have this line in my NextCloud config.php, NC fails with a 500 Internal Server Error:

'memcache.distributed' => '\\OC\\Memcache\\Redis',

I have not yet been able to ascertain what the server error is, exactly. I have not found an error in the log file where this usually shows up, and I have checked other logs with no success. The rest of my config related to Redis is:

'filelocking.enabled' => true,
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => '/var/run/redis/redis-server.sock',
    'port' => 0,
    'timeout' => 0,
    'dbindex' => 0,
  ),

Any help would be appreciated.

I’d similar issue

Solve removing socket configuration and add following

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

Did you setup Unix Socket in Redis before? E.g. under /etc/redis/redis.conf

Unix socket.

Specify the path for the Unix socket that will be used to listen for incoming connections. There is no default, so Redis will not listen on a unix socket when not specified.

unixsocket /var/run/redis/redis-server.sock

Did you setup Unix Socket in Redis before? E.g. under /etc/redis/redis.conf

I followed the redis configuration guide and there was no (direct) mention to it.

Following your suggestion, I tried with socks and configure on redis.conf and got internal server error code 500

under /etc/redis/redis.conf ,

unixsocket /var/run/redis/redis-server.sock
unixsocketperm 777

tried too with unixsocketperm 700

under config.php

 'memcache.local' => '\\OC\\Memcache\\Redis',
 'redis' => 
 array (
     'host' => '/var/run/redis/redis.sock',
     'port' => 0,  
  ),
 'memcache.locking' => '\\OC\\Memcache\\Redis',

don’t know what I’m doing wrong.

Hello cgasp,
you can try to use this configuration

array (
   'host' => '127.0.0.1',
   'port' => 6379,
)

This is not a recommended configuration, but you can figure out if redis is working without caring about unix sockets.

Additionally you can check if redis is working:

redis-cli
  ping  # answer should be PONG
  set key 1 10  # writing example value in redis db
  monitor # live monitoring redis
  flushall # flush redis cache / empty db

This docu is quite old one (for NC 13), you can find newer here: Memory caching — Nextcloud latest Administration Manual latest documentation

check if file exist:

ls -la /var/run/redis/redis.sock

On CentOS and Fedora install redis and php-pecl-redis. It will not start automatically, so you must use your service manager to start redis, and to launch it at boot as a daemon.

Be sure to set the right permissions on redis.sock so that your webserver can read and write to it. For this you typically have to add the webserver user to the redis group:

usermod -a -G redis www-data

Please restart the Web server, php and Redis after config was changed. E.g.:

sudo systemctl restart httpd.service #for Centos
#OR
sudo service apache2 restart #for Ubuntu

My Redis config:

unixsocket /var/run/redis/redis-server.sock

My Nextcloud config:

  'filelocking.enabled' => true,
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'memcache.distributed' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
     'host'     => '/var/run/redis/redis-server.sock',
     'port'     => 0,
     'timeout'  => 1.5,
  ),
1 Like