Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-84491

auth_ldap fails to initalize when removing users sessions in scheduled task

    • MOODLE_405_STABLE
    • mdl-84491_redis_connection_405
    • mdl-84491_redis_connection_500
    • mdl-84491_redis_connection_main
    • Difficult
    • Hide

      Setup Requirements

      1. We need to install a Redis instance on the local machine and ensure it's running at 127.0.0.1:6379. Refer to this page on how to install Redis https://redis.io/docs/install/install-redis/.
      2. Ensure your machine has the PHP-Redis extension enabled by checking the PHP info page. Moodle provides an overview on the following page: Site administration > Server > PHP info.
        If the Redis extension has not been installed, you can install it by running the below command:
        pecl install redis

        Please visit https://developer.redis.com/develop/php/ for detailed information on how to do the installation.

      3. During the unit testing, if enabled, please disable the Xdebug on your PHP CLI config.

      Running the PHPUnit test suite for Redis session handler

      1. Open your config.php and add the following code to the end of it:
        define(
          'TEST_SESSION_REDIS_HOST',
          '127.0.0.1:6379'
        );

        ATTENTION: If you skip this step, all unit tests for Redis will be skipped!

      2. Execute PHPUnit tests and make sure all the tests in lib/tests/session_redis_test.php are passed: php vendor/bin/phpunit lib/tests/session/redis_test.php

      Manual testing

      1. Edit the config.php, remove any extra session configuration you have (just in case) and add the following lines: 
        $CFG->autologinguests = 0;
        $CFG->session_handler_class = '\core\session\redis';
        $CFG->session_redis_host = '127.0.0.1';
        $CFG->session_redis_port = 6379;
        $CFG->session_redis_database = 0;
        $CFG->session_redis_prefix = 'mdl_';
        $CFG->session_redis_acquire_lock_timeout = 120;
        $CFG->session_redis_lock_expire = 7200;
      2. Purge caches executing: php admin/cli/purge_caches.php
      3. Open a browser and login into the instance
      4. In a terminal, execute: redis-cli flushall
      5. Refresh the browser page
      6. VERIFY that you are redirected to the login page.
      Show
      Setup Requirements We need to install a Redis instance on the local machine and ensure it's running at 127.0.0.1:6379 . Refer to this page on how to install Redis https://redis.io/docs/install/install-redis/ . Ensure your machine has the PHP-Redis extension enabled by checking the PHP info page. Moodle provides an overview on the following page: Site administration > Server > PHP info. If the Redis extension has not been installed, you can install it by running the below command: pecl install redis Please visit https://developer.redis.com/develop/php/ for detailed information on how to do the installation. During the unit testing, if enabled, please disable the Xdebug on your PHP CLI config. Running the PHPUnit test suite for Redis session handler Open your config.php and add the following code to the end of it: define(   'TEST_SESSION_REDIS_HOST' ,   '127.0.0.1:6379' ); ATTENTION: If you skip this step, all unit tests for Redis will be skipped! Execute PHPUnit tests and make sure all the tests in lib/tests/session_redis_test.php are passed: php vendor/bin/phpunit lib/tests/session/redis_test.php Manual testing Edit the config.php, remove any extra session configuration you have (just in case) and add the following lines:  $CFG->autologinguests = 0; $CFG->session_handler_class = '\core\session\redis'; $CFG->session_redis_host = '127.0.0.1'; $CFG->session_redis_port = 6379; $CFG->session_redis_database = 0; $CFG->session_redis_prefix = 'mdl_'; $CFG->session_redis_acquire_lock_timeout = 120; $CFG->session_redis_lock_expire = 7200; Purge caches executing: php admin/cli/purge_caches.php Open a browser and login into the instance In a terminal, execute: redis-cli flushall Refresh the browser page VERIFY that you are redirected to the login page.
    • Hide

      Code verified against automated checks.

      Checked MDL-84491 using repository: https://github.com/ngandrass/moodle.git

      More information about this report

      Built on: Thu Jun 5 09:08:19 UTC 2025

      Show
      Code verified against automated checks. Checked MDL-84491 using repository: https://github.com/ngandrass/moodle.git MOODLE_405_STABLE (0 errors / 0 warnings) [branch: mdl-84491_redis_connection_405 | CI Job ] MOODLE_500_STABLE (0 errors / 0 warnings) [branch: mdl-84491_redis_connection_500 | CI Job ] main (0 errors / 0 warnings) [branch: mdl-84491_redis_connection_main | CI Job ] More information about this report Built on: Thu Jun 5 09:08:19 UTC 2025

      Hello,

      I'm encountering error when using redis as session manager but only in a scheduled task, I confirmed that redis work properly for the rest.

      To me, it seems really similar to this error here: https://tracker.moodle.org/browse/MDLSITE-7818 as the stack trace is mostly the same.

      Steps to reproduce:

      1. Enable LDAP server authentication
      2. Setup redis as session handler
      3. Remove synced user from LDAP
      4. Run the task \auth_ldap\task\sync_task from CLI or GUI

      This should produce the following error:

      Scheduled task failed: Synchronisierung von LDAP-Nutzerkonten (auth_ldap\task\sync_task),Das Einrichten der Redis-Sitzung ist fehlgeschlagen. Bitte benachrichtigen Sie die Administrator/innen.
      Backtrace:
      * line 750 of /lib/classes/session/redis.php: call to core\session\redis->init()
      * line 616 of /lib/classes/session/redis.php: call to core\session\redis->init_redis_if_required()
      * line 576 of /lib/classes/session/manager.php: call to core\session\redis->get_sessions_by_userid()
      * line 1005 of /lib/classes/session/manager.php: call to core\session\manager::get_sessions_by_userid()
      * line 842 of /auth/ldap/auth.php: call to core\session\manager::destroy_user_sessions()
      * line 55 of /auth/ldap/classes/task/sync_task.php: call to auth_plugin_ldap->sync_users_update_callback()
      * line 410 of /lib/classes/cron.php: call to auth_ldap\task\sync_task->execute()
      * line 194 of /admin/cli/scheduled_task.php: call to core\cron::run_inner_scheduled_task()
      

            Unassigned Unassigned
            olivierwenger Olivier Wenger
            Votes:
            5 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.