[SOLVED] Nextcloud 17 redis, session.save_path

Nextcloud version (eg, 12.0.2): 17.0
Operating system and version (eg, Ubuntu 17.04): Docker image (Debian)
Apache or nginx version (eg, Apache 2.4.25): Apache 2.4.38
PHP version (eg, 7.1): 7.3.10

The issue you are facing:
Frequently I see issues in the logs like this:

Error PHP session_write_close(): Failed to write session data (redis). Please verify that the current setting of session.save_path is correct (tcp://redis:6379?database=2) at /var/www/html/lib/private/Session/Internal.php

I can see using redis-cli that database 2 on the host is filling with PHP session information, and most of the time things work fine and I disregard the error. But once in a while a session will hang such that I cannot successfully process any HTTP requests (e.g., load a page on the UI) without deleting cookies on that browser (other sessions for the same user are unaffected). The HTTP requests simply never complete, which I assume is because the session is locked.

The /var/www/html/.user.ini file remains unedited from what ships with the Docker image. I’m at a loss to diagnose the problem further; wondering if anyone here has had the same issue.

Is this the first time you’ve seen this error? (Y/N): N

Steps to replicate it:

  1. Configure Nextcloud with Redis cache
  2. Use Web UI
  3. Observe error in log
  4. Occasionally suffer hung session

The output of your Nextcloud log in Admin > Logging:
See above.

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):
Snipped to limit to what I think is relevant:

‘memcache.distributed’ => ‘\\OC\\Memcache\\Redis’,
‘redis’ => 
array (
  ‘host’ => ‘redis’,
  ‘port’ => 6379,
  ‘timeout’ => 0,
  ‘password’ => ‘’,
  ‘dbindex’ => 0,
‘filelocking.enabled’ => true,
‘filelocking.ttl’ => 3600,
‘memcache.locking’ => ‘\\OC\\Memcache\\Redis’,

The output of your Apache/nginx/system log in /var/log/____:

Nothing relevant here


Unfortunately I’m not well-informed about redis. So actually I’m not sure if this is even correct syntax:

Even if … I’m wondering if this setting is contrary to your configuration in the config.php where you have:

Do you think, this might cause this issue and should better be set to “2” as well?
I understand it works most of the time, but … I don’t know.

Something else which came to my mind: ulimit
Is your server used very intensively? Maybe some file/ session limits are hit. Can you check your ulimit configuration in /etc/profile, /etc/profile.d/* and furthermore /etc/security/limits.conf?
If redis is running as user “redis” you probably need to allow more “open files” (ulimit -n) or “max user processes” (ulimit -u) or something similar.

With effects on HTTP, these limits might even be worth to check for the web server user as well.

I have not experienced this issue, but I’m curious which version of Redis you’re running. I can see they’ve had problems like this in general with some versions they released.

I also vaguely remember flaky networking issues with Docker depending on the docker version and how it is configured. How are you running the containers?

@Schmu I didn’t configure the database number that Nextcloud is using; it did that all on its own. Database zero appears to be where Nextcloud caches precompiled assets, whereas database 2 seems to be used for PHP sessions. My user load is very low (like five users total), so I doubt I’m running out of file handles.

@linucksrox I’m running redis-5.0.5 under Kubernetes; there are no network-related errors in the logs.

I did see something related to older versions of php-redis giving this error, but I don’t know how to check which version is included in the Nextcloud Docker image.

The session.save_path parameter can definitely been found in the PHP configuration and is not a Redis related parameter. Concerning the Redis configuration I would only remove the password parameter if non has been set to prevent possible problems.

You mean you don’t know how to get the docker version? I believe you just run docker version in the terminal but I’m not entirely sure how this works with k8s.

@linucksrox I mean I don’t know how to check which version of php-redis is included in the Docker image.

I’m not sure, but maybe you can run docker exec -it [container-name] redis-server --version

@linucksrox php-redis is a PHP module installed in Nextcloud that is a client for communicating with redis servers.

Got it. Looks like the version is defined in the Dockerfile: https://github.com/nextcloud/docker/blob/master/17.0/apache/Dockerfile
For Nextcloud 17-apache, it’s php-redis 4.3.0

There’s apparently a bug in php-redis that has yet to be fixed.


Dang, that’s unfortunate, but at least you identified the issue :+1:

OK, the solution appears to be to disable session locking in /usr/local/etc/php/conf.d/redis-session.ini:

redis.session.locking_enabled = 0