First of all there are about 5 magento installations on this server..
Join the club ;)
We've seen it happen as well on servers with multiple Magento installations.
Currently we are fixing it by prepending the cron command with the flock command which makes sure only a single instance of the same cron can run based on a lock file. We are currently using something like this:
* * * * * flock -w 1 /path/to/some/lock/file.lock php /path/to/magento/installation/bin/magento cron:run
@hostep Thanks, your a life saver! Magento.. get on this!
Be aware that you still might run into more cron job problems. This won't fix everything. I still see cases where the cronjob status in the database is still at running even though the cronjob no longer runs (for example due to the jobs getting killed because the server ran out of memory).
Which then in turn causes a whole bunch of new jobs being inserted with status pending and they never get handled and only pile up forever, until someone goes manually in the database and cleans up those supposedly "running" jobs.
But that's being handled in https://github.com/magento/magento2/issues/11002 (even though there is no solution as far as I'm aware)
Just a quick update here: for some reason I can not understand yet, it looks like when using the flock solution, that parallel execution of cronjobs doesn't work properly anymore, which is kinda strange, since the main cronjob spawns other cron processes in the background which aren't being locked by flock, so I don't quite understand what is happening there.
(this comment is based on something I saw a month or two ago, using Magento 2.1.11 if I remember correctly)
For anyone that stumbles upon this old issue, Magento now has built-in locking for CRON processes. Details can be found here: https://devdocs.magento.com/guides/v2.3/install-gde/install/cli/install-cli-subcommands-lock.html
Most helpful comment
Join the club ;)
We've seen it happen as well on servers with multiple Magento installations.
Currently we are fixing it by prepending the cron command with the
flockcommand which makes sure only a single instance of the same cron can run based on a lock file. We are currently using something like this: