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

Some ad-hoc tasks fail when run from cron with keep-alive flag

XMLWordPrintable

    • MOODLE_402_STABLE, MOODLE_403_STABLE, MOODLE_404_STABLE
    • MOODLE_403_STABLE, MOODLE_404_STABLE
    • MDL-80911-403
    • MDL-80911-404
    • MDL-80911-main
    • Hide

      Initial setup

      1. Install the test plugin using the below command 

        git clone git@github.com:klao/tool_adhocbug.git admin/tool/adhocbug

      2. Login as admin and finish the upgrade process.
      3. Create at least one course.
      4. Note: For Moodle 4.4+, you may need to add $CFG->debug_developer_use_pretty_exceptions = false; to config.php because the test plugin will show some warning messages.

      Testing

      1. Navigate to [Your_Moodle_URL]/admin/tool/adhocbug/index.php
      2. Click the Run task button.
      3. Open your terminal.
      4. Run the below command 

        php admin/cli/adhoc_task.php --execute --keep-alive=59

      5. Verify that you will not see the Class "grade_item" not found error.
      6. Verify that you will see: YAAAAAAYYYYYY! The ad-hoc task ran successfully!
      7. Click the Run task button again.
      8. Verify that you will not see the Class "grade_item" not found error.
      9. Verify that you will see: YAAAAAAYYYYYY! The ad-hoc task ran successfully!
      10. Cancel the terminal.
      11. Navigate to [Your_Moodle_URL]/admin/tool/adhocbug/index.php
      12. Click the Run task button.
      13. Open your terminal.
      14. Run the below command 

        php admin/cli/cron.php

      15. Verify that you will not see the Class "grade_item" not found error.
      16. Verify that you will see: YAAAAAAYYYYYY! The ad-hoc task ran successfully!
      17. Click the Run task button again.
      18. Verify that you will not see the Class "grade_item" not found error.
      19. Verify that you will see: YAAAAAAYYYYYY! The ad-hoc task ran successfully!
      20. Cancel the terminal.

       

      Show
      Initial setup Install the test plugin using the below command  git clone git @github .com:klao/tool_adhocbug.git admin/tool/adhocbug Login as admin and finish the upgrade process. Create at least one course. Note : For Moodle 4.4+, you may need to add $CFG->debug_developer_use_pretty_exceptions = false; to config.php because the test plugin will show some warning messages. Testing Navigate to [Your_Moodle_URL] /admin/tool/adhocbug/index.php Click the Run task button. Open your terminal. Run the below command  php admin/cli/adhoc_task.php --execute --keep-alive= 59 Verify that you will not see the Class "grade_item" not found error. Verify that you will see: YAAAAAAYYYYYY! The ad-hoc task ran successfully! Click the Run task button again. Verify that you will not see the Class "grade_item" not found error. Verify that you will see: YAAAAAAYYYYYY! The ad-hoc task ran successfully! Cancel the terminal. Navigate to [Your_Moodle_URL] /admin/tool/adhocbug/index.php Click the Run task button. Open your terminal. Run the below command  php admin/cli/cron.php Verify that you will not see the Class "grade_item" not found error. Verify that you will see: YAAAAAAYYYYYY! The ad-hoc task ran successfully! Click the Run task button again. Verify that you will not see the Class "grade_item" not found error. Verify that you will see: YAAAAAAYYYYYY! The ad-hoc task ran successfully! Cancel the terminal.  
    • 6
    • Team Hedgehog 2024 Sprint 2.1

      Description

      Some ad-hoc tasks fail with Class not found fatal error when they are started from the cli/adhoc_task.php --keep-alive=59, but run normally and succeed when run from the "normal" cli/cron.php.

      A specific example, the get_moduleinfo_data() function triggers this behavior.

      Steps to reproduce

      You can find little plugin at https://github.com/klao/tool_adhocbug that we wrote to help reproducing this error.

      1. Install it in your test Moodle. (Well, check the code first that it's not doing something nasty. But it's very simple with just one page and an ad-hoc task.)
      2. Create at least one course with at least one course module.
      3. Add the * * * * * /usr/bin/php /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59 to your crontab, and log its output somewhere.
      4. Navigate to the http://your.test.moodle/admin/tool/adhocbug/index.php page and click the "Run task" button.
      5. Look at the cron output and see that it's failing with Class "grade_item" not found error.
      6. Disable the "keep-alive" cron runner, and next time the task is retried it will succeed.

      Note for Moodle 4.2 or higher

      In Moodle 4.2 the default cron script has this "keep-alive" behavior enabled by default. (See: https://tracker.moodle.org/browse/MDL-77186). So, to reproduce this bug, you don't need the additional cli/adhoc_task.php ... in your crontab. So, in the above list:

      • skip #3.
      • Observe the task failing.
      • Change the default crontab line to: admin/cli/cron.php --no-keep-alive.
      • Wait until the "keep-aliving" instances exit (or kill them).
      • The next time the ad-hoc task is retried it will succeed.

      Note that this buggy behavior doesn't always happen with this setup (regular cron with "keep-alive" enabled by default). I was able to reproduce it a few times, but not reliably. The `cli/adhoc_task.php --execute --keep-alive=59` always triggers this bug, even in Moodle 4.2.

      Notes

      Most of the regular ad-hoc tasks run just fine when started from "keep-alive" cron jobs. It's one obscure plugin where we noticed this behavior. But it makes the bug that much more devious, as it's not clear that the problem is not with the plugin, but with how the task is run.

      I have tested this with the latest 4.1 and 4.2 Moodle versions.

      Hat tip to Katalin Lukacs Toth lukc@zhaw.ch who discovered the bug!

            huongn@moodle.com Huong Nguyen
            klao Mihaly Barasz
            Safat Shahin Safat Shahin
            Sara Arjona (@sarjona) Sara Arjona (@sarjona)
            Kim Jared Lucas Kim Jared Lucas
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 2 days, 30 minutes
                2d 30m

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