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

Redis session is not working

XMLWordPrintable

    • MOODLE_404_STABLE
    • MOODLE_404_STABLE
    • MDL-81480-main
    • Hide

      1. Setup Requirements

      1. To test the Redis cluster with other features that have been provided by the existing system, such as TLS/SSL, Auth Password, please follow the instructions on Usage section at https://github.com/meirzamoodle/middleware-tutorials-redis-cluster-tls/tree/main#usage
      2. To the single Redis unit testing, we need to install a single Redis on 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/.
      3. Ensure your machine has the PHP-Redis extension by checking on the Info PHP page. There are a lot of ways to check the PHP Info Page. Moodle has provided it on the Site Admin > Server > PHP info.
        If it 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.

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

      2. Steps to run the PHPUnit for single Redis session

      1. Open config.php and add the below codes:

        define(
          'TEST_SESSION_REDIS_HOST',
          '127.0.0.1'
        );

      2. Make sure all the tests in lib/tests/session_redis_test.php are passed.

      3. Steps to run the PHPUnit for Redis cluster session

      1. Open config.php and add the below codes:

        define(
          'TEST_SESSION_REDIS_HOSTCLUSTER',
          '172.23.0.11,172.23.0.12,172.23.0.13,172.23.0.14,172.23.0.15,172.23.0.16'
        );
        define(
          'TEST_SESSION_REDIS_ENCRYPTCLUSTER',
          ['verify_peer' => false, 'verify_peer_name' => false],
        );
        define(
          'TEST_SESSION_REDIS_AUTHCLUSTER',
          'foobared'
        );

      2. Make sure all the tests in lib/tests/session_redis_cluster_test.php are passed.

      4. Manual testing: Single redis

      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;  // Optional.
        $CFG->session_redis_database = 0;  // Optional, default is db 0.
        $CFG->session_redis_prefix = 'qa.sess.'; // Optional, default is don't set one.
        $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.

      5. Manual testing: Redis Cluster

      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 = '172.23.0.11,172.23.0.12,172.23.0.13,172.23.0.14,172.23.0.15,172.23.0.16';
        $CFG->session_redis_auth = 'foobared';
        $CFG->session_redis_encrypt = ['verify_peer' => false, 'verify_peer_name' => false];
        $CFG->session_redis_database = 0;  // Optional, default is db 0.
        $CFG->session_redis_prefix = 'qa.sess.'; // Optional, default is don't set one.
        $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. Download flushall-cluster.sh and put the file in the directory where you clone the Redis cluster repo.
      1. In a terminal, execute:

        sh flushall-cluster.sh

      2. Refresh the browser page
      3. VERIFY that you are redirected to the login page.
      Show
      1. Setup Requirements To test the Redis cluster with other features that have been provided by the existing system, such as TLS/SSL, Auth Password, please follow the instructions on Usage section at https://github.com/meirzamoodle/middleware-tutorials-redis-cluster-tls/tree/main#usage To the single Redis unit testing, we need to install a single Redis on 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 by checking on the Info PHP page. There are a lot of ways to check the PHP Info Page. Moodle has provided it on the Site Admin > Server > PHP info. If it 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. 2. Steps to run the PHPUnit for single Redis session Open config.php and add the below codes: define(   'TEST_SESSION_REDIS_HOST' ,   '127.0.0.1' ); Make sure all the tests in lib/tests/session_redis_test.php are passed. 3. Steps to run the PHPUnit for Redis cluster session Open config.php and add the below codes: define(   'TEST_SESSION_REDIS_HOSTCLUSTER' ,   '172.23.0.11,172.23.0.12,172.23.0.13,172.23.0.14,172.23.0.15,172.23.0.16' ); define(   'TEST_SESSION_REDIS_ENCRYPTCLUSTER' ,   [ 'verify_peer' => false , 'verify_peer_name' => false ], ); define(   'TEST_SESSION_REDIS_AUTHCLUSTER' ,   'foobared' ); Make sure all the tests in lib/tests/session_redis_cluster_test.php are passed. 4. Manual testing: Single redis 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;  // Optional. $CFG->session_redis_database = 0;  // Optional, default is db 0. $CFG->session_redis_prefix = 'qa.sess.'; // Optional, default is don't set one. $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. 5. Manual testing: Redis Cluster 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 = '172.23.0.11,172.23.0.12,172.23.0.13,172.23.0.14,172.23.0.15,172.23.0.16'; $CFG->session_redis_auth = 'foobared'; $CFG->session_redis_encrypt = ['verify_peer' => false, 'verify_peer_name' => false]; $CFG->session_redis_database = 0;  // Optional, default is db 0. $CFG->session_redis_prefix = 'qa.sess.'; // Optional, default is don't set one. $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 Download flushall-cluster.sh and put the file in the directory where you clone the Redis cluster repo. In a terminal, execute: sh flushall-cluster.sh Refresh the browser page VERIFY that you are redirected to the login page.
    • 2
    • Team Hedgehog 2024 Sprint 1.4

      This issue was detected while executing MDLQA-18725. It seems the changes from MDL-63128 introduced a regression in the Redis session handler.

      Steps to reproduce:

      0) Have a localhost redis server configured and working.

      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;  // Optional.
      $CFG->session_redis_database = 0;  // Optional, default is db 0.
      $CFG->session_redis_prefix = 'qa.sess.'; // Optional, default is don't set one.
      $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

      Expected: you should be redirected to the login page because the session is destroyed.

      What happens: you are still logged in

       

        1. (2) 2 Passed -- (Main)MDL-81480.png
          (2) 2 Passed -- (Main)MDL-81480.png
          120 kB
        2. (3) 2 Passed -- (Main)MDL-81480.png
          (3) 2 Passed -- (Main)MDL-81480.png
          128 kB
        3. (4) 6 Passed -- (Main)MDL-81480.png
          (4) 6 Passed -- (Main)MDL-81480.png
          113 kB
        4. (5) 3 Passed -- (Main)MDL-81480.png
          (5) 3 Passed -- (Main)MDL-81480.png
          270 kB
        5. flushall-cluster.sh
          0.3 kB
        6. MDL-81480_Test2-Step2-OK.png
          MDL-81480_Test2-Step2-OK.png
          81 kB
        7. MDL-81480_Test3-Step2-OK.png
          MDL-81480_Test3-Step2-OK.png
          99 kB
        8. MDL-81480_Test4-Step6-OK.png
          MDL-81480_Test4-Step6-OK.png
          148 kB
        9. MDL-81480_Test5-Step3-OK.png
          MDL-81480_Test5-Step3-OK.png
          294 kB

            meirza.arson@moodle.com Meirza
            tusefomal Ferran Recio
            Raquel Ortega Raquel Ortega
            Ilya Tregubov Ilya Tregubov
            Kim Jared Lucas Kim Jared Lucas
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 day, 1 hour, 10 minutes
                1d 1h 10m

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