-
Bug
-
Resolution: Fixed
-
Minor
-
4.2.6, 4.3.3, 4.4
-
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.
- 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.)
- Create at least one course with at least one course module.
- 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.
- Navigate to the http://your.test.moodle/admin/tool/adhocbug/index.php page and click the "Run task" button.
- Look at the cron output and see that it's failing with Class "grade_item" not found error.
- 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!