Login loop when php session are saved in memcache : Current user is not logged in

Hello

Nextcloud version : 18.0.3 but I have exactly the same problem with v 17
Operating system and version : deb10
Apache version : apache2.4.38-3
PHP fpm version : 7.3.14-1~deb10u1
php-memcached : 3.1.3+2.2.0-1
memcache : 1.5.6-1.1

The issue you are facing:
When i try to enable session save in memcached in php.ini nextcloud break.
The first login is success full but then there is a login loop
If i disable session save everything work as expected

php.ini:

session.save_handler = memcached
session.save_path = '127.0.0.1:11211'

When I test memcache everything theems to work as expected (a php script to test session save is working correctly) :
number of visits: 12 Server IP: 192.168.x.10 Client IP: 192.168.x.22 Array ( [PHPSESSID] => djclotqr5jio0cjoc1mflpjduj )

If i clean my browser cache first login work then not.

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

Steps to replicate it:

  1. activate session save in memcache (/etc/php/7.3/fpm/php.ini)
  2. first login work
  3. the login loop with error Current user is not logged in

The output of your Nextcloud log in Admin > Logging:

First login:
{"reqId":"nQJKfBXSjiUA4fF3oPtS","level":0,"time":"2020-04-06T14:10:50+00:00","remoteAddr":"78.153.x","user":"--","app":"cron","method":"GET","url":"/cron.php","message":"Run OC\\Command\\CommandJob job with ID 908","userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:74.0) Gecko/20100101 Firefox/74.0","version":"18.0.3.0"}
{"reqId":"nQJKfBXSjiUA4fF3oPtS","level":0,"time":"2020-04-06T14:10:50+00:00","remoteAddr":"78.153.x","user":"--","app":"cron","method":"GET","url":"/cron.php","message":"Finished OC\\Command\\CommandJob job with ID 908 in 0 seconds","userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:74.0) Gecko/20100101 Firefox/74.0","version":"18.0.3.0"}

{"reqId":"WTWdyrAXuJWQxmnYxdCB","level":0,"time":"2020-04-06T14:11:06+00:00","remoteAddr":"78.153.x","user":"xxx_root","app":"no app in context","method":"GET","url":"/index.php/apps/files/","message":"Deprecated event type for OCA\\Files::loadAdditionalScripts: Symfony\\Component\\EventDispatcher\\GenericEvent","userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:74.0) Gecko/20100101 Firefox/74.0","version":"18.0.3.0"}

second login:
{"reqId":"3ZHszXwIbhd59kpjBTIb","level":0,"time":"2020-04-06T14:15:20+00:00","remoteAddr":"78.153.x","user":"--","app":"cron","method":"GET","url":"/cron.php","message":"Run OC\\Command\\CommandJob job with ID 914","userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:74.0) Gecko/20100101 Firefox/74.0","version":"18.0.3.0"}
{"reqId":"3ZHszXwIbhd59kpjBTIb","level":0,"time":"2020-04-06T14:15:20+00:00","remoteAddr":"78.153.x","user":"--","app":"cron","method":"GET","url":"/cron.php","message":"Finished OC\\Command\\CommandJob job with ID 914 in 0 seconds","userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:74.0) Gecko/20100101 Firefox/74.0","version":"18.0.3.0"}

{"reqId":"idx7y7wFdNIKfLWElqqv","level":0,"time":"2020-04-06T14:15:35+00:00","remoteAddr":"78.153.x","user":"--","app":"core","method":"GET","url":"/index.php/apps/files/","message":{"Exception":"OC\\AppFramework\\Middleware\\Security\\Exceptions\\NotLoggedInException","Message":"Current user is not logged in","Code":401,"Trace":[{"file":"/var/www/nextcloud/lib/private/AppFramework/Middleware/MiddlewareDispatcher.php","line":97,"function":"beforeController","class":"OC\\AppFramework\\Middleware\\Security\\SecurityMiddleware","type":"->","args":[{"__class__":"OCA\\Files\\Controller\\ViewController"},"index"]},{"file":"/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":97,"function":"beforeController","class":"OC\\AppFramework\\Middleware\\MiddlewareDispatcher","type":"->","args":[{"__class__":"OCA\\Files\\Controller\\ViewController"},"index"]},{"file":"/var/www/nextcloud/lib/private/AppFramework/App.php","line":125,"function":"dispatch","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->","args":[{"__class__":"OCA\\Files\\Controller\\ViewController"},"index"]},{"file":"/var/www/nextcloud/lib/private/AppFramework/Routing/RouteActionHandler.php","line":47,"function":"main","class":"OC\\AppFramework\\App","type":"::","args":["OCA\\Files\\Controller\\ViewController","index",{"__class__":"OC\\AppFramework\\DependencyInjection\\DIContainer"},{"_route":"files.view.index"}]},{"function":"__invoke","class":"OC\\AppFramework\\Routing\\RouteActionHandler","type":"->","args":[{"_route":"files.view.index"}]},{"file":"/var/www/nextcloud/lib/private/Route/Router.php","line":299,"function":"call_user_func","args":[{"__class__":"OC\\AppFramework\\Routing\\RouteActionHandler"},{"_route":"files.view.index"}]},{"file":"/var/www/nextcloud/lib/base.php","line":1008,"function":"match","class":"OC\\Route\\Router","type":"->","args":["/apps/files/"]},{"file":"/var/www/nextcloud/index.php","line":38,"function":"handleRequest","class":"OC","type":"::","args":[]}],"File":"/var/www/nextcloud/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php","Line":142,"CustomMessage":"--"},"userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:74.0) Gecko/20100101 Firefox/74.0","version":"18.0.3.0"}
{"reqId":"ufdxCJyJhHTtpKUHhCYV","level":0,"time":"2020-04-06T14:15:37+00:00","remoteAddr":"78.153.x","user":"--","app":"cron","method":"GET","url":"/cron.php","message":"Run OC\\Command\\CommandJob job with ID 915","userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:74.0) Gecko/20100101 Firefox/74.0","version":"18.0.3.0"}
{"reqId":"ufdxCJyJhHTtpKUHhCYV","level":0,"time":"2020-04-06T14:15:37+00:00","remoteAddr":"78.153.x","user":"--","app":"cron","method":"GET","url":"/cron.php","message":"Finished OC\\Command\\CommandJob job with ID 915 in 0 seconds","userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:74.0) Gecko/20100101 Firefox/74.0","version":"18.0.3.0"}

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

<?php
$CONFIG = array (
  'instanceid' => 'xxxx',
  'passwordsalt' => 'xxxxx',
  'secret' => 'xxxxx',
  'trusted_domains' =>
  array (
    0 => 'xxxxx',
    1 => 'xxxxx',
  ),
  'datadirectory' => '/data/nextcloud/',
  'dbtype' => 'mysql',
  'version' => '18.0.3.0',
  'overwrite.cli.url' => 'xxxx',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextcloud',
  'dbpassword' => 'xxxx',
  'installed' => true,
  'memcache.local' => '\\OC\\Memcache\\Memcached',
  'memcache.distributed' => '\\OC\\Memcache\\Memcached',
  'memcached_servers' =>
  array (
    0 =>
    array (
      0 => 'localhost',
      1 => 11211,
    ),
  ),
  'maintenance' => false,
  'mail_smtpmode' => 'smtp',
  'mail_sendmailmode' => 'smtp',
  'mail_from_address' => 'owncloud',
  'mail_domain' => 'xxxx',
  'mail_smtphost' => 'localhost',
  'mail_smtpport' => '25',
  'theme' => '',
  'loglevel' => 0,
  'updater.secret' => 'xxxxx',
);

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

78.153.x - - [06/Apr/2020:16:15:35 +0200] "POST /index.php/login HTTP/1.1" 303 1224 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:74.0) Gecko/20100101 Firefox/74.0"
78.153.x - - [06/Apr/2020:16:15:35 +0200] "GET /index.php/apps/files/ HTTP/1.1" 303 880 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:74.0) Gecko/20100101 Firefox/74.0"
78.153.x - - [06/Apr/2020:16:15:35 +0200] "GET /index.php/login?redirect_url=/index.php/apps/files/ HTTP/1.1" 200 4816 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:74.0) Gecko/20100101 Firefox/74.0

no error in apache log

Thanks!

As far as I understoodd this option is not really supported. Please see the following discussion about it:

This should be supported.
If you need HA, how can you share php session between two (and more) server if you cannot use redis or memcache?

If you have an other website with php session in memcache, you can’t host them together???

1 Like