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

Memcached sessions lose lock early

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 2.6
    • 2.6
    • Libraries
    • MOODLE_26_STABLE
    • MOODLE_26_STABLE
    • w44_MDL-42485_m26_memcachedlocktimeout
    • Hide

      0/ configure server to use memcached sessions
      1/ set memsession acquire timeout to 50 seconds (see config-dist.php for instructions)
      2/ crate a simple script that includes config.php and does sleep(200)
      3/ open other browser window (same browser!!!) and go to moodle page (same site!!!)
      4/ the browser should wait for 50 seconds and then continue

      Show
      0/ configure server to use memcached sessions 1/ set memsession acquire timeout to 50 seconds (see config-dist.php for instructions) 2/ crate a simple script that includes config.php and does sleep(200) 3/ open other browser window (same browser!!!) and go to moodle page (same site!!!) 4/ the browser should wait for 50 seconds and then continue

    Description

      Memcached sessions will loose their lock after max_execution_time seconds, regardless of if Moodle later extends the time using set_time_limit(). This is because the memcached session handler uses max_execution_time to set the max lock duration at session_start().

      This means that long running scripts (like backups and restores) won't hold their session lock for long (only 30 seconds in a default php install).

      Now, because of this, there is a potential solution, you could do something like:

      public static function start() {
          $default = ini_get('max_execution_time');
          set_time_limit($CFG->session_memcached_lock_expire);
          parent::start();
          set_time_limit($default);
      }

      I fully acknowledge that this is probably horrible in many ways.

      You can see the memcached session locking logic at:
      https://github.com/php-memcached-dev/php-memcached/blob/master/php_memcached_session.c

      Attachments

        Issue Links

          Activity

            People

              skodak Petr Skoda
              emerrill Eric Merrill
              Damyon Wiese Damyon Wiese
              Dan Poltawski Dan Poltawski
              Michael de Raadt Michael de Raadt
              David Woloszyn, Huong Nguyen, Jake Dallimore, Meirza, Michael Hawkins, Raquel Ortega, Safat Shahin, Stevani Andolo
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                18/Nov/13