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

Read only sessions option throw exception with tool_mobile_get_public_config mobile when using redis sessions

    XMLWordPrintable

Details

    • MOODLE_39_STABLE
    • MOODLE_39_STABLE
    • read-only-session
    • Hide
      1. Setup Redis server: https://docs.moodle.org/en/Redis_cache_store 
        • Install redis-server
        • Install Redis PHP driver
        • Configure Redis in Moodle
      2. Configure Redis as the session handler: 

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

      3. Turn on read only sessions:

        $CFG->enable_read_only_sessions = true;
        

      4. Run this web service (you'll need to replace moodle.local by your local Moodle URL):

        curl -v -X POST 'http://moodle.local/lib/ajax/service.php?info=tool_mobile_get_public_config' -d '[{"siteUrl": "http://moodle.local", "index": 0, "methodname":"tool_mobile_get_public_config", "args":{}}]'

      5. Confirm you don't get an exception
      Show
      Setup Redis server: https://docs.moodle.org/en/Redis_cache_store   Install redis-server Install Redis PHP driver Configure Redis in Moodle Configure Redis as the session handler:  $CFG->session_redis_host = '127.0.0.1'; $CFG->session_redis_port = 6379; $CFG->session_redis_acquire_lock_timeout = 5; $CFG->session_handler_class = '\core\session\redis'; Turn on read only sessions: $CFG->enable_read_only_sessions = true; Run this web service (you'll need to replace moodle.local by your local Moodle URL): curl -v -X POST 'http://moodle.local/lib/ajax/service.php?info=tool_mobile_get_public_config' -d '[{"siteUrl": "http://moodle.local", "index": 0, "methodname":"tool_mobile_get_public_config", "args":{}}]' Confirm you don't get an exception

    Description

      I'm not too sure on this as a patch, but it resolves the issue.

      On startup, the mobile app does a POST as:

      curl -X POST 'http://localhost/lib/ajax/service.php?info=tool_mobile_get_public_config&XDEBUG_SESSION_START=VSCODE' -d '[\{"siteUrl": "http://localhost", "index": 0, "methodname":"tool_mobile_get_public_config", "args":{}}]'

      If read-only sessions and redis are enabled, this hits the handler_read() function.

      In there, if finds there is not yet a session in redis, then, if write-lock is needed, returns '' else returns false.

      Since false is returned, we throw later on.

      diff --git a/lib/classes/session/redis.php b/lib/classes/session/redis.php
      index ff11a66129..f2da4525b0 100644
      --- a/lib/classes/session/redis.php
      +++ b/lib/classes/session/redis.php
      @@ -257,8 +257,10 @@ class redis extends handler {
                       $this->lock_session($id);
                   }
                   $sessiondata = $this->connection->get($id);
      -            if ($sessiondata === false && $this->requires_write_lock()) {
      -                $this->unlock_session($id);
      +            if ($sessiondata === false) {
      +                if ($this->requires_write_lock()) {
      +                    $this->unlock_session($id);
      +                }
                       return '';
                   }
                   $this->connection->expire($id, $this->timeout);
      

      Attachments

        Issue Links

          Activity

            People

              donbowman Don Bowman
              donbowman Don Bowman
              Brendan Heywood Brendan Heywood
              Sara Arjona (@sarjona) Sara Arjona (@sarjona)
              Janelle Barcega Janelle Barcega
              Votes:
              3 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                15/Jun/20

                Time Tracking

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