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

Lock: improve coding error feedback

    XMLWordPrintable

    Details

    • Testing Instructions:
      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
    • Affected Branches:
      MOODLE_27_STABLE, MOODLE_28_STABLE
    • Fixed Branches:
      MOODLE_29_STABLE
    • Pull Master Branch:
      MDL-49747-task-error-improvement

      Description

      Split from and see MDL-49740 for context

      This issue / patch covers just the improvement to the task exception thrown when a lock isn't properly released.

        Attachments

          Activity

            People

            Assignee:
            brendanheywood Brendan Heywood
            Reporter:
            brendanheywood Brendan Heywood
            Peer reviewer:
            Damyon Wiese Damyon Wiese
            Integrator:
            Dan Poltawski Dan Poltawski
            Tester:
            Martin Mastny Martin Mastny
            Participants:
            Component watchers:
            Andrew Lyons, Dongsheng Cai, Huong Nguyen, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Fix Release Date:
              11/May/15