Cron does not terminate and need a lot of ram

Nextcloud version: 19.0.0
Operating system and version: 18.04.4.LTS
Apache or nginx version: nginx/1.18.0 (fpm-fcgi)
Database: mysql 10.1.44
PHP version: 7.4.8

apps
Enabled:
 - accessibility: 1.5.0
 - activity: 2.12.0
 - apporder: 0.10.0
 - bruteforcesettings: 1.6.0
 - circles: 0.19.3
 - cloud_federation_api: 1.2.0
 - comments: 1.9.0
 - contactsinteraction: 1.0.0
 - dav: 1.15.0
 - federatedfilesharing: 1.9.0
 - federation: 1.9.0
 - files: 1.14.0
 - files_automatedtagging: 1.9.0
 - files_downloadactivity: 1.8.0
 - files_pdfviewer: 1.8.0
 - files_rightclick: 0.16.0
 - files_sharing: 1.11.0
 - files_trashbin: 1.9.0
 - files_versions: 1.12.0
 - files_videoplayer: 1.8.0
 - flowupload: 1.0.0
 - groupfolders: 6.0.6
 - imageconverter: 1.2.1
 - logreader: 2.4.0
 - lookup_server_connector: 1.7.0
 - nextcloud_announcements: 1.8.0
 - notifications: 2.7.0
 - oauth2: 1.7.0
 - password_policy: 1.9.1
 - photos: 1.1.0
 - privacy: 1.3.0
 - provisioning_api: 1.9.0
 - quota_warning: 1.8.0
 - ransomware_protection: 1.7.0
 - richdocuments: 3.7.3
 - serverinfo: 1.9.0
 - settings: 1.1.0
 - sharebymail: 1.9.0
 - spreed: 9.0.1
 - support: 1.2.1
 - survey_client: 1.7.0
 - systemtags: 1.9.0
 - theming: 1.10.0
 - twofactor_backupcodes: 1.8.0
 - twofactor_totp: 4.1.3
 - twofactor_u2f: 5.1.0
 - updatenotification: 1.9.0
 - user_ldap: 1.9.0
 - viewer: 1.3.0
 - workflowengine: 2.1.0
Disabled:
 - admin_audit
 - encryption
 - files_external
 - firstrunwizard
 - issuetemplate
 - recommendations
 - socialsharing_email
 - text

The issue you are facing:
Hello, everyone,

currently i have the problem that the nextcloud cron is filling 76% of my memory and i can’t figure out why. Could someone help me with this?
image

Is this the first time you’ve seen this error? (Y/N):
Yes

Steps to replicate it:

  1. Restart Server
  2. Wait

The output of your Nextcloud log in Admin > Logging:

No entries because of the cron

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

<?php
$CONFIG = array (
  'passwordsalt' => '***REMOVED SENSITIVE VALUE***',
  'trusted_domains' => 
  array (
    0 => 'mmmbox.mmmgroup.com',
  ),
  'datadirectory' => '***REMOVED SENSITIVE VALUE***',
  'skeletondirectory' => '***REMOVED SENSITIVE VALUE***',
  'tempdirectory' => '/tmp/nextcloud',
  'dbtype' => 'mysql',
  'version' => '19.0.0.12',
  'dbname' => '***REMOVED SENSITIVE VALUE***',
  'dbhost' => '***REMOVED SENSITIVE VALUE***',
  'dbtableprefix' => 'oc_',
  'dbuser' => '***REMOVED SENSITIVE VALUE***',
  'dbpassword' => '***REMOVED SENSITIVE VALUE***',
  'mysql.utf8mb4' => true,
  'installed' => true,
  'loglevel' => 0,
  'logtimezone' => 'Europe/Berlin',
  'logdateformat' => 'd.m.y H:i:s',
  'maintenance' => false,
  'secret' => '***REMOVED SENSITIVE VALUE***',
  'ldapIgnoreNamingRules' => false,
  'forcessl' => true,
  'mail_smtpmode' => 'smtp',
  'mail_from_address' => '***REMOVED SENSITIVE VALUE***',
  'mail_domain' => '***REMOVED SENSITIVE VALUE***',
  'mail_smtphost' => '***REMOVED SENSITIVE VALUE***',
  'mail_smtpport' => '25',
  'ldapProviderFactory' => '\\OCA\\User_LDAP\\LDAPProviderFactory',
  'ldapUserCleanupInterval' => 51,
  'lost_password_link' => '***REMOVED SENSITIVE VALUE***',
  'instanceid' => '***REMOVED SENSITIVE VALUE***',
  'mail_sendmailmode' => 'smtp',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_smtpauth' => 1,
  'mail_smtpname' => '',
  'mail_smtppassword' => '',
  'overwrite.cli.url' => 'https://mmmbox.mmmgroup.com',
  'memcache.local' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => 'localhost',
    'port' => 6379,
  ),
  'default_language' => 'de',
  'default_locale' => 'de',
  'trashbin_retention_obligation' => 'auto, 60',
  'versions_retention_obligation' => 'auto, 60',
  'theme' => 'mmmbox',
  'simpleSignUpLink' => 'false',
  'activity_expire_days' => '90',
  'default_language' => 'de',
  'default_locale' => 'de',
  'trashbin_retention_obligation' => 'auto, 60',
  'versions_retention_obligation' => 'auto, 60',
  'theme' => 'mmmbox',
  'simpleSignUpLink' => 'false',
  'activity_expire_days' => '90',
);

The output of your Apache/nginx/system log in /var/log/____:

no errors

Please deactive all cron-processes for Nextcloud and then start it manually. Perhaps you find an error:

sudo -u username /usr/bin/php.7.4 ....

Test also with the standard php version.

sudo -u username php ...

Test also your php7.4 settings.

thanks for your quick response,

if I start the cron by hand, it runs through without any problems.
No error message or similar can be detected.

Perhaps the wrong user or wrong environment variables with CRON. No further idea. Sorry.
How often do you start the cron job?

the cron is started every 5 minutes there are no other parameters, everything I have specified for the cron is shown in the screenshot above

the backup does not run at the time the cron hangs and no other task i know of

as user is set the same user I used to run the cron manually

I think the cron starts to fast.
Set the cron to every hour for testing.
Look in your php-settings (7.4 / normal). Please test also the normal php-version in /usr/bin.

which php
php --version

I don’t know what you mean by normal.
I have installed another php 7.0 because of a relatively old application. With the path information I want to prevent that nextcloud is running with it.

i just followed the instructions, there are also 5 minutes
https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/background_jobs_configuration.html?highlight=cron#cron

Yes. But if you use cron every 5 minutes it does not work because it runs multiple because of the long time of execution.

But perhaps it is a problem with your old operation system. With Ubuntu 20.04 LTS or Debian Buster 10 you get a newer php-version than php 7.0 . Which operation system is installed?

php 7.0 and Ubuntu:
https://packages.ubuntu.com/de/xenial/php
This is Ubuntu 16.04 LTS and very old.

php 7.0 and Debian:
https://packages.debian.org/de/stretch/php
This is Debian Stretch and also a little bit old.

Both systems are supported but perhaps not a good solution for nextcloud.
You must use for running nextcloud a php-version from another source than the normal distribution.

https://packages.ubuntu.com/de/bionic/php
uses php 7.2

Perhaps you can dist-upgrade to Ubuntu 20.04 LTS

In your database you have a table oc_jobs or jobs. This is a list of all jobs executed during a cronjob. There is even a column with execution duration.

With this list you can perhaps crosscheck with the apps installed if everything is working as supposed. From you apps, there is stuff like imageconverter which could create a lot of load on the system.

That is great, and how long took the run?
The 5 minute cycle was changed recently, before it was about 15 minutes. Drawback of longer cycles are that notification mails will be sent with a larger delay. Normally the cronjob creates a lockfile, so there shouldn’t be any overlap (the new process makes sure the old one finished).
if everything takes long, you might take a look into your database caching settings.

If you have redis, I’d use it as file-locking cache as well that takes away load from the normal database.

1 Like

since I have installed php 7.4, should this not be a problem for the time I think?

this execution duration is given in seconds? then it would be 86 seconds in total

so according to the github page of the imageconverter this is only done by hand


we have some iphone users, so I installed this.

I have now done it 3 times by hand and it takes maximum 2 minutes.

thanks for the tip with the redis filelock, have it set up now
https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/caching_configuration.html?highlight=file%20lock%20redis#id2

since the changeover the cronjob also takes less than one minute

Which task is taking most of the time?

With the reduction, did the memory consumption decrease as well?

i can’t say yet, because the cron seems to hang only 2 times a day

1 Like

then it’s just a matter of time. Don’t forget to dump the jobs-table so you can track this issue. I’m not sure about the logs (perhaps needs to increase log level), perhaps there it’s mentioned which job is started, so in case of a crash you just need to check which one was started last.

These are the 3 biggest jobs, then come 10 or so with an execution time of 1

OCA\Activity\BackgroundJob\ExpireActivities 	16
OCA\Files_Versions\BackgroundJob\ExpireVersions 	15
OCA\Files\BackgroundJob\ScanFiles 	15

so I can just empty the oc_jobs?

I am having this exact problem, I have ensured the php config has been done correctly. This has only started after I have moved to nextcloud 19, could this be an issue with php7.4 ?

Nextcloud version: 19.0.0
Operating system and version: 20.04 LTS
Apache or nginx version: nginx/1.18.0 (fpm-fcgi)
Database: mysql 10.1.44
PHP version: 7.4.8

No just backup the table after each run to see how long it took. Don’t empty the table, it’s needed.

1 Like

so i couldn’t see any difference except for the new timestamps, i started an excerpt here.

The problem is that the cron gets stuck at night and I would rather sleep than wait for the cron :confused:

but it always seems to get stuck at the same time; once at 23:30 and at 5:30(CEST)

but I have to agree @Chris_Aldred , I’ve only had this problem since Nextcloud 19
Whereby only on the Ubuntu system, I manage another one on Debian and there it does not occur, the configuration is almost identical

You can run a cron afterwards to query the values from the database. Also the logs might give hints :wink:

I am not sure if all the jobs do something at each run. Like this, I’d think that these are some daily routines, not sure like for the trashbin and stuff like that. But I don’t know enough to tell you which has changed for NC 19. Perhaps change the run time a bit, perhaps on your ubuntu system it collides with a different cronjob.