Allowed memory size of xxx bytes exhausted

Hi all, I was on NextCloud 13.0.6. I updated to 14. All went well but I noticed lots of old errors in the logs that ultimately were being caused by having a stale version of nginx and openssl. Easiest way to fix was to move this instance to a wholly new FreeBSD jail based on the current FreeBSD. In doing so, I recreated the nginx config, moved the nextcloud install, and installed the needed packages (nginx, php, php-pgsql, etc.). If I run a script that calls phpinfo() it works fine and gives me the expected text, but NextCloud is just unable to do anything except throw a 500 error.

(and yes I saw the similarly-titled other topic, but it wasn’t of help to me)


Nextcloud version 14.0.3:
Operating system and version: newly created jail on FreeNAS/FreeBSD 11:
Apache or nginx version: nginx 1.14.0_12,2:
PHP version (eg, 7.1): php 7.3

The issue you are facing:
PHP Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 12374000625787947544 bytes) in /opt/nextcloud/lib/private/Security/CSRF/CsrfToken.php on line 57

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

Steps to replicate it:

  1. I just moved my NextCloud install to a brand new FreeNAS/FreeBSD jail
  2. Visit https://mynextcloud.server
  3. This error shows up in the logs

The output of your Nextcloud log in Admin > Logging:

Can't get to it

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

$CONFIG = array (
  'instanceid' => 'xxx',
  'passwordsalt' => 'xxx',
  'secret' => 'C/xxx/R9yvFvXMC',
  'trusted_domains' => 
  array (
    0 => '192.168.1.22',
    1 => 'xxx',
    2 => 'xxx2',
  ),
  'datadirectory' => '/mnt/nextcloud_files',
  'overwrite.cli.url' => 'http://192.168.1.22',
  'dbtype' => 'pgsql',
  'version' => '14.0.3.0',
  'installed' => true,
  'mail_from_address' => 'daemon',
  'mail_smtpmode' => 'smtp',
  'mail_domain' => 'xxx',
  'ldapIgnoreNamingRules' => false,
  'mail_smtpauthtype' => 'LOGIN',
  'mail_smtpauth' => 1,
  'mail_smtphost' => 'smtp.gmail.com',
  'mail_smtpport' => '465',
  'mail_smtpsecure' => 'ssl',
  'mail_smtpname' => 'xxx',
  'mail_smtppassword' => 'xxx',
  'forcessl' => true,
  'forceSSLforSubdomains' => true,
  'theme' => '',
  'maintenance' => false,
  'logfile' => '/mnt/nextcloud_files/nextcloud.log',
  'loglevel' => 2,
  'trashbin_retention_obligation' => 'auto',
  'dbname' => 'owncloud',
  'dbhost' => 'xxx',
  'dbuser' => 'xxx',
  'dbpassword' => 'xxx',
  'htaccess.RewriteBase' => '/',
  'updater.release.channel' => 'stable',
  'updater.server.url' => 'https://updates.nextcloud.com/updater_server/',
  'ldapProviderFactory' => '\\OCA\\User_LDAP\\LDAPProviderFactory',

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

2018/10/17 22:53:25 [error] 56279#101852: *1 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Allowed memory size of 536870912 bytes exhausted (tried to allocate 12374000625787947544 bytes) in /opt/nextcloud/lib/private/Security/CSRF/CsrfToken.php on line 57" while reading response header from upstream, client: 192.168.1.214, server: xxxx, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "xxxx"

hows memory allocation defined in

/etc/php/7.X/cli/php.ini

or

/etc/php/7.X/apache2/php.ini

?

In /usr/local/etc/php.ini I have

memory_limit = 512M

but this isn’t that I have too little memory allocated… it’s that the getEncryptedValue() function in CsrfToken.php is trying to allocate 12 exabytes of memory (12374000625787947544). You can see in that error message that there is in fact 536870912 (512MB) of memory available.

I initially suspected something in the SSL setup of nginx, but the phpinfo page serves up just fine over SSL.

I am running php-fpm but i didn’t remember needing to do anything special to configure it. When I upgraded the jail it updated openssl, nginx, php, and php-fpm, so a lot has changed under the hood.

thanks again

oh, wow, and did you check the .htaccess as well? (unsure if nginx uses .htaccess files, im currently only using apache):

<IfModule mod_php5.c\>
  php_value upload_max_filesize 16G
  php_value post_max_size 16400M
  php_value memory_limit 512M
  ...

Just trying to give you any hints possible which may lead to a running instance :wink:

Thanks a lot. Yes I’ve adjusted those other parameters in php.ini as well, though they’d only affect timeouts on upload. nginx doesn’t use .htaccess files, but the access should be working since it worked before and I’ve copied all the config files as well as the actual nextcloud install dir.

Again I appreciate your brainstorming!

OK I figured it out! It looks like Nextcloud doesn’t support PHP 7.3. I downgraded to PHP 7.2 and now it’s all working again.

missed that as well, but glad you have a solution now.

Nextcloud 15 should support PHP 7.3, yet I have same issue, as reported.

Same problem here with Nextcloud 15 and PHP 7.3

Hi everyone,

I’m not sure if you were able to solve your issues already. I just did a little search and found the following, which might be helpful:

One user wrote on https://github.com/nextcloud/server/issues/5249#issuecomment-308415569

Probably fixed it with installing and configuring opcache. At the moment it is working.
If it appears again, I’ll tell you.

Opcache settings to use are here:
https://docs.nextcloud.com/server/15/admin_manual/configuration_server/server_tuning.html#enable-php-opcache

opcache.enable=1
opcache.enable_cli=1
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.memory_consumption=128
opcache.save_comments=1
opcache.revalidate_freq=1

I hope it helps

Just a quick note. I caused this bug by mistakenly updating the php 7.2 cli ini memory limit from “-1” to 512M as recommended.

In short
/etc/php/cli/php.ini had -1 for memory limit, and it should stay that way
Returning the setting back to -1 this error went away.

3 Likes

HUGE THANKS @rahlquist !!
I was searching for a solution for hours and your comment finally solved the problem for me.

Though I think it’s quite strange that even though I had a memory limit of “512M” configured in there nextcloud seemed to say it could only allocate 2MB…

THANK YOU @rahlquist !!! Fighting Curl in php 7.3, won that batttle to find cron had not run in some time… Ty…