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

Failing adhoc tasks sometimes run twice ignoring nextruntime/faildelay

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Minor Minor
    • None
    • 4.1 regressions
    • Tasks
    • None

      Under specific circumstances and due to the caching of queued tasks ($miniqueue) in the task managers get_next_adhoc_task() function a task that was marked as failed is getting re-executed right after, ignoring the new nextruntime/faildelay.

      For the bug to get triggered it is required that the number of "unique tasks" (tasks from different classes) do not change between subsequent calls of manager::get_next_adhoc_task():

              $uniquetasksinqueue = array_map(
                  ['\core\task\manager', 'adhoc_task_from_record'],
                  $DB->get_records_sql(
                      'SELECT classname FROM {task_adhoc} WHERE nextruntime < :timestart GROUP BY classname',
                      ['timestart' => $timestart]
                  )
              );        if (!isset(self::$numtasks) || self::$numtasks !== count($uniquetasksinqueue)) {
                  self::$numtasks = count($uniquetasksinqueue);
                  self::$miniqueue = [];
              }

      The occurrence of the bug can be seen in the task log showing multiple entries for the same task id with a started timestamp just a few seconds apart. I also verified the bug by reviewing the code and inserting a debug output into the foreach loop of the get_next_adhoc_task() function:

       

      if ($record->nextruntime >= $timestart) {
          mtrace("Running a task with its nextruntime ($record->nextruntime) in the future (now: $timestart). Oups!");
      }

      This bug was introduced with MDL-67648 and is still present on the master branch.

            Unassigned Unassigned
            jojoob Johannes Burk
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

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