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

Table mdl_sessions does not get cleaned

XMLWordPrintable

    • MOODLE_405_STABLE
    • MOODLE_405_STABLE
    • MDL-84051-405
    • MDL-84051-main
    • Hide

      Initial setup

      1. Clone https://github.com/moodlehq/moodle-docker
      2. Run the following commands:

        export MOODLE_DOCKER_WWWROOT=[Path to your moodle code]
        export MOODLE_DOCKER_DB=pgsql
        export MOODLE_DOCKER_DB_PORT=9999
        export MOODLE_DOCKER_PHPUNIT_EXTERNAL_SERVICES=true
        cp config.docker-template.php $MOODLE_DOCKER_WWWROOT/config.php
        bin/moodle-docker-compose up -d 

      Database connection

      1. Use your preferred Database editor. Example: Dbeaver
      2. Create PostgreSQL connection with the below detail:
        1. Host: localhost
        2. Port: 9999
        3. Username: moodle
        4. Password: m@0dl3ing
        5. Database: moodle

      Unit testing

      To test the memcached unit testing, a tester must add the below consts to the config.php

      define('TEST_SESSION_MEMCACHED_SERVER', 'memcached0:11211');
      define('TEST_SESSION_MEMCACHED_PREFIX', 'memc.sess.key.');
      

      RUN

       

      bin/moodle-docker-compose exec webserver php admin/tool/phpunit/cli/init.php
      bin/moodle-docker-compose exec webserver vendor/bin/phpunit lib/tests/session/memcached_test.php

       

      VERIFY that the lib/tests/session/memcached_test.php is OK.

      1.3. Testing memcached session handler

      1. Open config.php and add the below codes after the "$CFG->wwwroot" line:

        $CFG->session_handler_class = '\core\session\memcached';
        $CFG->session_memcached_save_path = 'memcached0:11211';

      2. Delete or truncate data in m_sessions table
      3. Login to your Moodle as admin
      4. Run the below SQL query

        SELECT * FROM mdl_sessions

      5. VERIFY that there is data in the m_sessions table
      6. Run the below command on your terminal

        php admin/cli/kill_all_sessions.php

      7. VERIFY that there is no data in the m_sessions table

      2. File handler

      2.1. Testing file session handler

      1. Open config.php and add the below codes after the "$CFG->wwwroot" line:

        $CFG->session_handler_class = '\core\session\file';
        $CFG->session_file_save_path = $CFG->dataroot.'/sessions';

      2. Delete or truncate data in m_sessions table
      3. Login to your Moodle as admin
      4. Run the below SQL query

        SELECT * FROM m_sessions

      5. VERIFY that there is data in the m_sessions table
      6. Run the below command on your terminal

        php admin/cli/kill_all_sessions.php

      7. VERIFY that there is no data in the m_sessions table
      Show
      Initial setup Clone https://github.com/moodlehq/moodle-docker Run the following commands: export MOODLE_DOCKER_WWWROOT=[Path to your moodle code] export MOODLE_DOCKER_DB=pgsql export MOODLE_DOCKER_DB_PORT= 9999 export MOODLE_DOCKER_PHPUNIT_EXTERNAL_SERVICES= true cp config.docker-template.php $MOODLE_DOCKER_WWWROOT/config.php bin/moodle-docker-compose up -d Database connection Use your preferred Database editor. Example: Dbeaver Create PostgreSQL connection with the below detail: Host: localhost Port: 9999 Username: moodle Password: m@0dl3ing Database: moodle Unit testing To test the memcached unit testing, a tester must add the below consts to the config.php define( 'TEST_SESSION_MEMCACHED_SERVER' , 'memcached0:11211' ); define( 'TEST_SESSION_MEMCACHED_PREFIX' , 'memc.sess.key.' ); RUN :    bin/moodle-docker-compose exec webserver php admin/tool/phpunit/cli/init.php bin/moodle-docker-compose exec webserver vendor/bin/phpunit lib/tests/session/memcached_test.php   VERIFY that the lib/tests/session/memcached_test.php is OK. 1.3. Testing memcached session handler Open config.php and add the below codes after the "$CFG->wwwroot" line: $CFG->session_handler_class = '\core\session\memcached' ; $CFG->session_memcached_save_path = 'memcached0:11211' ; Delete or truncate data in m_sessions table Login to your Moodle as admin Run the below SQL query SELECT * FROM mdl_sessions VERIFY that there is data in the m_sessions table Run the below command on your terminal php admin/cli/kill_all_sessions.php VERIFY that there is no data in the m_sessions table 2. File handler 2.1. Testing file session handler Open config.php and add the below codes after the "$CFG->wwwroot" line: $CFG->session_handler_class = '\core\session\file' ; $CFG->session_file_save_path = $CFG->dataroot. '/sessions' ; Delete or truncate data in m_sessions table Login to your Moodle as admin Run the below SQL query SELECT * FROM m_sessions VERIFY that there is data in the m_sessions table Run the below command on your terminal php admin/cli/kill_all_sessions.php VERIFY that there is no data in the m_sessions table
    • Hide

      Code verified against automated checks.

      Checked MDL-84051 using repository: https://github.com/meirzamoodle/moodle.git

      More information about this report

      Built on: Fri Jan 31 02:57:17 AM UTC 2025

      Show
      Code verified against automated checks. Checked MDL-84051 using repository: https://github.com/meirzamoodle/moodle.git MOODLE_405_STABLE (0 errors / 0 warnings) [branch: MDL-84051-405 | CI Job ] main (0 errors / 0 warnings) [branch: MDL-84051-main | CI Job ] More information about this report Built on: Fri Jan 31 02:57:17 AM UTC 2025
    • Show
      Launching automatic jobs for branch MDL-84051 -405 https://ci.moodle.org/view/Testing/job/DEV.02%20-%20Developer-requested%20PHPUnit/18165/ PHPUnit (sqlsrv) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/62052/ Behat (NonJS - boost and classic) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/62053/ Behat (Firefox - boost) Launching automatic jobs for branch MDL-84051 -main https://ci.moodle.org/view/Testing/job/DEV.02%20-%20Developer-requested%20PHPUnit/18166/ PHPUnit (sqlsrv) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/62054/ Behat (NonJS - boost and classic) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/62055/ Behat (Firefox - boost) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/62056/ Behat (Firefox - classic) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/62057/ App tests (stable app version) Built on: Thu Feb 6 08:30:21 AM UTC 2025
    • 2
    • Team Dragons 2025 Sprint 1.2

      Hi,

      I can't really provide technical details, but I noticed, on our 4.5 sites, that the mdl_sessions table fills up and never gets cleaned by the scheduled task. After awhile, you can end up with over a million entries, which is causing the task to eventually stop working.

      We found out this behaviour after someone reported that editing a user profile took minutes and sometimes generated a lack of memory error.

      I reported the issue here: https://moodle.org/mod/forum/discuss.php?d=464679.

        1. MDL-84051.png
          161 kB
          Ron Carl Alfon Yu
        2. MDL-84051-1_3.png
          468 kB
          Ron Carl Alfon Yu
        3. MDL-84051-2.png
          409 kB
          Ron Carl Alfon Yu

            meirza.arson@moodle.com Meirza
            flizotte2 François Lizotte
            Stevani Andolo Stevani Andolo
            Safat Shahin Safat Shahin
            Ron Carl Alfon Yu Ron Carl Alfon Yu
            Votes:
            9 Vote for this issue
            Watchers:
            21 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 2 days, 5 hours, 42 minutes
                2d 5h 42m

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