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

Scheduled task cli not releasing cron lock

XMLWordPrintable

    • MOODLE_27_STABLE, MOODLE_28_STABLE
    • MOODLE_27_STABLE, MOODLE_28_STABLE
    • MDL-49740-locking-bugs
    • Hide

      Dump a simple script with this coding error somewhere:

      <?php

      define('CLI_SCRIPT', true);
      require(_DIR_ . '/../../../../config.php');
      require_once("$CFG->libdir/clilib.php");

      $factory = \core\lock\lock_config::get_lock_factory('cron');
      $lock = $factory->get_lock('core_cron', 10);

      Prior to patch you get a stack trace from the context of the shutdown handler.

      After the patch when you run this the exception has extra details which tells you exactly where the lock was opened that should be released:

      PHP Fatal error: Uncaught exception 'coding_exception' with message 'Coding error detected, it must be fixed by a programmer: A lock was created but not released at:
      /var/www/cqu-he-moodle/admin/tool/task/cli/fail.php on line 8

      Code should look like:

      $factory = \core\lock\lock_config::get_lock_factory('cron');
      $lock = $factory->get_lock(1);
      $lock->release(); // Locks must ALWAYS be released like this.

      ' in /var/www/cqu-he-moodle/lib/classes/lock/lock.php:118

      Show
      Dump a simple script with this coding error somewhere: <?php define('CLI_SCRIPT', true); require(_ DIR _ . '/../../../../config.php'); require_once("$CFG->libdir/clilib.php"); $factory = \core\lock\lock_config::get_lock_factory('cron'); $lock = $factory->get_lock('core_cron', 10); Prior to patch you get a stack trace from the context of the shutdown handler. After the patch when you run this the exception has extra details which tells you exactly where the lock was opened that should be released: PHP Fatal error: Uncaught exception 'coding_exception' with message 'Coding error detected, it must be fixed by a programmer: A lock was created but not released at: /var/www/cqu-he-moodle/admin/tool/task/cli/fail.php on line 8 Code should look like: $factory = \core\lock\lock_config::get_lock_factory('cron'); $lock = $factory->get_lock(1); $lock->release(); // Locks must ALWAYS be released like this. ' in /var/www/cqu-he-moodle/lib/classes/lock/lock.php:118

      Today I was debugging an task api issue and was trying to use the admin/tool/task/cli/schedule_task.php CLI to debug what was going on.The CLI was complaining about lock's not being released and showing fairly useless stack trace.

      After a bit of digging I added some extra debugging info into the locking factory for postgres which clearly shows where the original lock was created and show this in lock::__destruct so that it's obvious exactly where the coding error is. As it turns out it's actually the schedule_task.php which wasn't releasing the cron lock properly when the task lock fails.

      In addition to this the auto_release methods in both db factory classes then create new lock objects and don't release them which further obfuscates the stacks and error messages.

      I'll have a patch ready shortly with adds the debugging to all of the various lock factories, fixes the auto_release bug and also fixes the cli script bug.

            brendanheywood Brendan Heywood
            brendanheywood Brendan Heywood
            Damyon Wiese Damyon Wiese
            Dan Poltawski Dan Poltawski
            Adrian Greeve Adrian Greeve
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

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