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

When PHP runs out of memory, tasks are treated as still running instead of being marked as failed

XMLWordPrintable

    • MOODLE_402_STABLE, MOODLE_403_STABLE
    • MOODLE_402_STABLE, MOODLE_403_STABLE
    • MDL-80684-MOODLE_402_STABLE-fail_running_tasks_on_shutdown
    • MDL-80684-MOODLE_403_STABLE-fail_running_tasks_on_shutdown
    • MDL-80684-master-fail_running_tasks_on_shutdown
    • Hide

      Testing instructions

      Adhoc tasks

      1. Open mod/assign/feedback/editpdf/classes/task/convert_submission.php in your editor
      2. Rewrite the execute method:

            public function execute() {
                $data = '';
         
                while (true) {
                    $data .= 'test';
                }
            }
        

      3. Create a test.php with the following contents

        <?php
        define('CLI_SCRIPT', true);
         
        require_once 'config.php';
         
        $taskid = \core\task\manager::queue_adhoc_task(new \assignfeedback_editpdf\task\convert_submission());\core\cron::run_adhoc_task($taskid);
        \core\cron::run_adhoc_task($taskid);
        

      4. Run the test.php file in cli and you should experience an OOM error.
      5. Headover to the admin/tool/task/adhoctasks.php page and you should see 1 job in the 'Ad hoc tasks failed' column.

      Scheduled tasks

      1. Rewrite the contents of the execute method in this file lib/classes/task/automated_backup_task.php:

            public function execute() {
                $data = '';
         
                while (true) {
                    $data .= 'test';
                }
           }
        

      2. Create a test.php with the following contents

        <?php
        define('CLI_SCRIPT', true);
         
        require_once 'config.php';
         
        $scheduled_task = \core\task\manager::get_scheduled_task(\core\task\automated_backup_task::class);
         
        \core\task\manager::run_from_cli($scheduled_task);
        

      3. Run the test.php file in cli and you should experience an OOM error.
      4. Head over to the /admin/tool/task/scheduledtasks.php page and find the job, it should now have a faildelay set, indicating it has been marked as failed.
      Show
      Testing instructions Adhoc tasks Open mod/assign/feedback/editpdf/classes/task/convert_submission.php in your editor Rewrite the execute method: public function execute() { $data = '' ;   while (true) { $data .= 'test' ; } } Create a test.php with the following contents <?php define( 'CLI_SCRIPT' , true);   require_once 'config.php' ;   $taskid = \core\task\manager::queue_adhoc_task( new \assignfeedback_editpdf\task\convert_submission());\core\cron::run_adhoc_task( $taskid ); \core\cron::run_adhoc_task( $taskid ); Run the test.php file in cli and you should experience an OOM error. Headover to the admin/tool/task/adhoctasks.php page and you should see 1 job in the 'Ad hoc tasks failed' column. Scheduled tasks Rewrite the contents of the execute method in this file lib/classes/task/automated_backup_task.php: public function execute() { $data = '' ;   while (true) { $data .= 'test' ; } } Create a test.php with the following contents <?php define( 'CLI_SCRIPT' , true);   require_once 'config.php' ;   $scheduled_task = \core\task\manager::get_scheduled_task(\core\task\automated_backup_task:: class );   \core\task\manager::run_from_cli( $scheduled_task ); Run the test.php file in cli and you should experience an OOM error. Head over to the /admin/tool/task/scheduledtasks.php page and find the job, it should now have a faildelay set, indicating it has been marked as failed.

      When PHP gets killed because of OOM, tasks are not marked as failed and moodle thinks they are still running.

      With my fix following the testing instructions should result in the task being marked as failed.

            frederikmillingpytlick Frederik Milling Pytlick
            frederikmillingpytlick Frederik Milling Pytlick
            David Woloszyn David Woloszyn
            Andrew Lyons Andrew Lyons
            Huong Nguyen Huong Nguyen
            Votes:
            4 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 2 days, 5 hours, 50 minutes
                2d 5h 50m

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