When starting a Scheduler Task from the command line (with scheduler:run), it starts a task that is still running.
This bug only occurs when scheduled tasks are started from the command line. Joomla can start scheduled tasks in three ways: the Lazy Scheduler, Web Cron, and the command line (php cli/joomla.php scheduler:run), as described in How to Run Scheduled Tasks from the Command Line. The first two are not affected.
#__ and the ID):UPDATE #__scheduler_tasks SET locked = UTC_TIMESTAMP() WHERE id = 1;php cli/joomla.php scheduler:run --id=1scheduler:run --all).The task is not started, because it is locked and the lock is younger than the Task Timeout.
The task runs again. In practice: when a cronjob runs scheduler:run --all every minute and a task takes longer than that, the next process starts the same task while the first is still running it. The first process can then not release its lock and ends with exit code 4 (NO_RELEASE).
Web Cron and the Lazy Scheduler start no task while any task is running, so they don't have this problem.
Add the same condition as in Task::acquireLock() to buildLockQuery(): lock the task only when locked is NULL or older than the Task Timeout. If no row is updated, the task is running, and runTask() returns no task.
Joomla 6.1, PHP 8.3, MySQL 8.
The Good to know section of the documentation page above mentions this behaviour; that paragraph can be simplified once this is fixed.
Possibly related: #44322 (Task Scheduler Looping). There, a long task run from an external cronjob every minute is started again every 6 minutes or so. In both issues a task is started again while it is still running, and its next execution has not been moved forward yet. What is different: in our current issue the task can be started again at once, while its lock is still valid. In #44322 the restarts come only after about 6 minutes: the default Task Timeout of 300 seconds plus the next cron minute. So there the lock seems to hold until it expires. The cronjob in that issue is used for Web Cron, not to run scheduler:run on the command line. Whether both issues have the same cause is not confirmed.
| Labels |
Added:
No Code Attached Yet
bug
|
||
Please test PR #48592.