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

Allow customisation of Redis session handler errors

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.9.9, 3.10.6, 3.11.2, 4.0, 4.1
    • 4.1
    • Authentication, Performance
    • MOODLE_310_STABLE, MOODLE_311_STABLE, MOODLE_39_STABLE, MOODLE_400_STABLE, MOODLE_401_STABLE
    • MOODLE_401_STABLE
    • MDL-72283_allow-customisation-of-redis-session-handler-errors
    • Hide

      The changes are covered by unit tests.

      Setup
      1. Install the PHP Redis extension (replace "X" as your server's PHP version, e.g. 8.0)

        sudo apt update && sudo apt install -y phpX-redis

      2. Restart your web server.
      3. Confirm the redis PHP extension is enabled: "php -i | grep redis" - You should see a bunch of lines related to redis.
      4. Install redis. e.g. using Docker

        docker run --name redis -p 6379:6379 -d redis

      5. Setup redis as the session handler, e.g. copy the following to your config.php:

        $CFG->session_handler_class = '\core\session\redis';
        $CFG->session_redis_host = '127.0.0.1';
        $CFG->session_redis_port = 6379;
        $CFG->session_redis_acquire_lock_timeout = 2;

      6. Install the session breaker plugin to help with testing:

        git clone https://github.com/catalyst/moodle-tool_sessionbreaker/ admin/tool/sessionbreaker

      Test
      1. Visit this page, which will lock the session for 20 seconds: /admin/tool/sessionbreaker/bad.php?wait=20
      2. In a second tab immediately load this page: /admin/tool/sessionbreaker/good.php
      3. Confirm after roughly 2 seconds it throws an exception eg

        Unable to obtain session lock for sid: pvga0j242m within 0 days 0 hours 0 minutes 2 seconds.
        It is likely that another page ([pid 1758327] workstation:/admin/tool/sessionbreaker/bad.php?wait=20), possibly in another browser tab, has caused this due to any of the following reasons:
        it has a long session lock; or
        the session lock was never released due to an error.
        You can try to close and re-open your browser or wait until the session lock timeout (0 days 20 hours 0 minutes 0 seconds) has passed. If this error persists, please notify the server administrator.
        

      Show
      The changes are covered by unit tests. Setup Install the PHP Redis extension (replace " X " as your server's PHP version, e.g. 8.0) sudo apt update && sudo apt install -y phpX-redis Restart your web server. Confirm the redis PHP extension is enabled: " php -i | grep redis " - You should see a bunch of lines related to redis. Install redis. e.g. using Docker docker run --name redis -p 6379:6379 -d redis Setup redis as the session handler, e.g. copy the following to your config.php: $CFG ->session_handler_class = '\core\session\redis' ; $CFG ->session_redis_host = '127.0.0.1' ; $CFG ->session_redis_port = 6379; $CFG ->session_redis_acquire_lock_timeout = 2; Install the session breaker plugin to help with testing: git clone https://github.com/catalyst/moodle-tool_sessionbreaker/ admin/tool/sessionbreaker Test Visit this page, which will lock the session for 20 seconds: /admin/tool/sessionbreaker/bad.php?wait=20 In a second tab immediately load this page: /admin/tool/sessionbreaker/good.php Confirm after roughly 2 seconds it throws an exception eg Unable to obtain session lock for sid: pvga0j242m within 0 days 0 hours 0 minutes 2 seconds. It is likely that another page ([pid 1758327] workstation:/admin/tool/sessionbreaker/bad.php?wait=20), possibly in another browser tab, has caused this due to any of the following reasons: it has a long session lock; or the session lock was never released due to an error. You can try to close and re-open your browser or wait until the session lock timeout (0 days 20 hours 0 minutes 0 seconds) has passed. If this error persists, please notify the server administrator.

    Description

      The exceptions raised by the Redis session handler are hardcoded in English.  It would be nice if these could be customised/internationalised.  For example, "unable to obtain session lock" is not all that useful to the end user.  They need to be told they have to close and re-open their browser, or to wait until the session lock timeout (usually 2 mins) has passed.

      I think this means (at minimum) that the "unable to obtain session lock" exception should be changed to a moodle_exception and a language pack installed.

      Attachments

        Issue Links

          Activity

            People

              Daniel Ziegenberg Daniel Ziegenberg
              chrisf Chris Fryer
              Brendan Heywood Brendan Heywood
              Jun Pataleta Jun Pataleta
              Angelia Dela Cruz Angelia Dela Cruz
              David Woloszyn, Huong Nguyen, Jake Dallimore, Michael Hawkins, Stevani Andolo, Matteo Scaramuccia, David Woloszyn, Huong Nguyen, Jake Dallimore, Michael Hawkins, Stevani Andolo
              Votes:
              2 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                28/Nov/22

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 2 hours
                  2h