Closed NoxWorld2660 closed 1 month ago
After checking the database, i noticed the "lastrun" field is updated correctly no matter what even if the task is failing. However the the "state" remains with the value "2" , which according to what i see in the UI, seems to be the value for "Running".
State of cronstasks seems to be :
I therefore digged into the code and tried to find a workaround or solution that would fix the remaining "Running" state issue without impacting anything else and found this : https://github.com/glpi-project/glpi/blob/10.0.16/src/MailCollector.php#L720
The following attempt is a wrong turn, doesn't work. A try-catch block already exists on the Cron , see next comment.
I just added
'state' => 1,
in the database update part. After checking, this is not a proper or suitable fix : the collect() method seems to be called for each mailcollector configured. If you have multiple mailcollector it will probably mess things up. But i only have 1 mail collector for now, so i will try if this solves my issue temporarily.
If it works, a slightly cleaner solution (just enough to support multiple mail collectors) would be to put a Try-Catch and that fix in the cronMailgate() foreach loop, and execute it only in case of errors, just to make sure the task status is correct for the next run before you exit the script in case of crashes.
Hope this will help. Il'l keep updating if relevant.
https://github.com/glpi-project/glpi/blob/10.0.16/src/MailCollector.php#L720
I just added
'state' => 1,
in the database update part.
This update referes to the MailCollector itself that has no state
property. Changing this should not have any impact on the crontask state itself.
If it works, a slightly cleaner solution (just enough to support multiple mail collectors) would be to put a Try-Catch and that fix in the cronMailgate() foreach loop, and execute it only in case of errors, just to make sure the task status is correct for the next run before you exit the script in case of crashes.
There is already a try/catch block to surround every crontask execution, see https://github.com/glpi-project/glpi/blob/308d15fad7f4fa09936e96048ed1206528f01722/src/CronTask.php#L1026-L1048
It may be possible that this try/catch block fails if the error is not recoverable. I am not sure, but I think it could be the case when the error is due to an execution that consume more memory than the configured limit to when the execution time reach the configured timeout. It may also happen if you are facing a fatal error of the PHP engine itself.
Check the cron.log
file to see if any issue is reported. Also, you could try to upgrade your PHP version from 8.2.10 to 8.2.23. If your problem is related to a PHP bug, then it may be fixed by this upgrade.
Thank you for your reply.
I still can't see any log about the mailgate anywhere, but i restarted the server and deleted old logs yesterday so, i might just not have crashed yet. I suspect Windows is not helping things to run smoothly either (already had an opcache bug related to windows).
Some part of my php.ini , maybe you can suggest improvements regarding logs or glpi cron :
max_execution_time = 300
memory_limit = 512M
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
I looked in glpi_cronstasklogs , and i can confirm sometimes it's missing the "Action Completed" part. The maximum elapsed time for the cronstasks_id=9 (the only mailgate collection i have configured) is 4.88s for 6 mails at once.
I will try to see if there is a PHP Bug somewhere, but i find it weird that a potential fatal error is not logged anywhere. Do you have any suggestion for further investigation ?
Is there anything in the cron.log
file? If this file is empty, then it may means that is is not writable by the webserver. Also, check if logging in files is allowed in Setup > General > System
.
I do have a few logs in cron.log, but just " XXXX start " + a timestamp. Example :
2024-09-11 14:58:01 [@servername]
Externe #1 : Démarrage mailgate
I do have a few logs in cron.log, but just " XXXX start " + a timestamp.
So it probably means that the PHP script is literally killed and cannot event log the failure.
Tips : Spacing the running schedule of the Cron / Scheduled task seems to help. I suspect sometimes the Windows Scheduled Task was triggered before the cron was able to finish , either killing the actual running script or queuing a lot of tasks and causing crash after a little while.
@cedric-anne , i only have 3 or 4 GLPI enabled tasks and using CLI , and changed the time frame of some tasks to be run at night. Is there a way to control which task is scheduled by the Cron ?
For example, i would like to do something like this, on the OS level with parameters given to cron.php :
Is there a way to control which task is scheduled by the Cron ?
mailgate
corresponds to the name displayed in the Setup > Automatic actions
page.
Also, please check if there is something, at Windows level, used to kill your cron script. I already see documentations in the wild that advice to use some tricks to automatically kill the PHP process of the GLPI cron when its execution time is too long. I do not remember if it was done by another scheduled task, an option, ... but anyway, killing the GLPI cron is a bad idea.
I close this issue as it is not a GLPI bug. Indeed, the GLPI cron script has some kind of semaphore logic that is used to prevent parallel executions and has an internal error management that exists to prevent your initial issue (as long as it is not killed by someone else).
This issue has been closed as we only track bugs here.
You can get community support on forums or you can consider taking a subscription to get professional support. You can also contact GLPI editor team directly.
Code of Conduct
Is there an existing issue for this?
Version
10.0.16
Bug description
Mailgate is almost constantly stuck in "running" state.
I can't find any relevant log in GLPI or PHP despite being in "log all" mode everywhere (php.ini & glpi). It occurs both in CLI and GLPI mode.
I tried to change the execution timing cycle a few times ( 1 min - 5 min - 10 min ) , and i also adapted the crontask (trying to run this in CLI under Windows Server 2019). The bug remains in every configuration i've tried.
I also made a Cron every 5 min to unlock that specific task through glpi console, it doesn't work either.
Note that my mail server is On-Prem, and i am gathering email through IMAP. The server sometimes seems slow though.
Relevant log output
No response
Page URL
No response
Steps To reproduce
No response
Your GLPI setup information
Informations sur le système, l'installation et la configuration
Server
GLPI constants
Libraries
Notifications
Plugins list
Anything else?
No response