Closed
Description
Preconditions (*)
magento 2.3.x
- Cron observer uses locks (db, cache, file or zookeper)
- The job is locked after
cron:run
is sent to shell
see this method
\Magento\Cron\Observer\ProcessCronQueueObserver::execute
The problem, I suppose, that magetno uses the same method to run all groups or one group
in \Magento\Cron\Observer\ProcessCronQueueObserver::execute
it creates commands in shell
if ($this->_request->getParam(self::STANDALONE_PROCESS_STARTED) !== '1'
&& $this->getCronGroupConfigurationValue($groupId, 'use_separate_process') == 1
) {
$this->_shell->execute(
$phpPath . ' %s cron:run --group=' . $groupId . ' --' . Cli::INPUT_KEY_BOOTSTRAP . '='
. self::STANDALONE_PROCESS_STARTED . '=1',
[
BP . '/bin/magento'
]
);
continue;
}
and only then, it runs the command like this
php bin/magento cron:run --group=index --bootstrap=standaloneProcessStarted=1
it goes to this part
$this->lockGroup(
$groupId,
function ($groupId) use ($currentTime, $jobsRoot) {
$this->cleanupJobs($groupId, $currentTime);
$this->generateSchedules($groupId);
$this->processPendingJobs($groupId, $jobsRoot, $currentTime);
}
);
Technically possible to remove all locks and run many bin/magento cron:run &
and see dozens of created processes in shell
e.g. indexer php bin/magento cron:run --group=index --bootstrap=standaloneProcessStarted=1
Steps to reproduce (*)
- Run
bin/magento cron:run &
a few times in background - See that it creates more than 1 process in shell
egphp bin/magento cron:run --group=index --bootstrap=standaloneProcessStarted=1
Expected result (*)
- If in shell one cron command is running the second should not be created
- only one unique shell command should be processed
- Lock for process or group should be checked before the command goes to shell
Actual result (*)
- Magento can create many processes at time
- May simultaneously running processes check locks wait and consumes server resources
- Lock for process or group is checked after the command is in shell
WORKAROUND:
Install each cron group separetely with flock instead adding default cron:run in crontab.
Metadata
Metadata
Assignees
Labels
Gate 3 Passed. Manual verification of the issue completed. Issue is confirmedGate 1 Passed. Automatic verification of issue format passedGate 4. Acknowledged. Issue is added to backlog and ready for developmentMay be fixed according to the position in the backlog.The issue has been reproduced on latest 2.3 releaseThe issue has been reproduced on latest 2.4-develop branchAffects non-critical data or functionality and does not force users to employ a workaround.Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Type
Projects
Status
Done