Occ command; PHP Fatal error, Allowed memory size of XXX bytes exhausted in docker fpm

Support intro

Sorry to hear you’re facing problems :slightly_frowning_face:

help.nextcloud.com is for home/non-enterprise users. If you’re running a business, paid support can be accessed via portal.nextcloud.com where we can ensure your business keeps running smoothly.

In order to help you as quickly as possible, before clicking Create Topic please provide as much of the below as you can. Feel free to use a pastebin service for logs, otherwise either indent short log examples with four spaces:

example

Or for longer, use three backticks above and below the code snippet:

longer
example
here

Some or all of the below information will be requested if it isn’t supplied; for fastest response please provide as much as you can :heart:

Nextcloud version (eg, 20.0.5): 24.0.2
Operating system and version (eg, Ubuntu 20.04): Ubuntu 20.04
Apache or nginx version (eg, Apache 2.4.25): nginx
PHP version (eg, 7.4): 8.0.20 FPM docker

The issue you are facing:
occ can’t run

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

Steps to replicate it:

  1. install nextcloud with docker nginx fpm official image and dcoker-compose Base version Fpm
  2. run the docker-compose -up d to start NC
  3. install NC
  4. docker exec -it nextcloud_app_1 /bin/bash
root@eaa33c5d5061:/var/www/html/apps# sudo -u www-data  php ../occ help            

Fatal error: Allowed memory size of 2097152 bytes exhausted (tried to allocate 442368 bytes) in /var/www/html/3rdparty/composer/autoload_real.php on line 35
root@eaa33c5d5061:/var/www/html/apps# 

The output of your Nextcloud log in Admin > Logging:

Fatal	webdav	Doctrine\DBAL\Exception\DeadlockException: An exception occurred while executing a query: SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction

    /var/www/html/3rdparty/doctrine/dbal/src/Connection.php - line 1780:

    Doctrine\DBAL\Driver\API\MySQL\ExceptionConverter->convert(Doctrine\DBA ... {}, Doctrine\DBAL\Query {})

    /var/www/html/3rdparty/doctrine/dbal/src/Connection.php - line 1719:

    Doctrine\DBAL\Connection->handleDriverException(Doctrine\DBA ... {}, Doctrine\DBAL\Query {})

    /var/www/html/3rdparty/doctrine/dbal/src/Connection.php - line 1173:

    Doctrine\DBAL\Connection->convertExceptionDuringQuery(Doctrine\DBA ... {}, "UPDATE `oc_ ... )", [ 1656744470 ... 0], [ 2,2,1,2,2])

    /var/www/html/lib/private/DB/Connection.php - line 294:

    Doctrine\DBAL\Connection->executeStatement("UPDATE `oc_ ... )", [ 1656744470 ... 0], [ 2,2,1,2,2])

    /var/www/html/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php - line 354:

    OC\DB\Connection->executeStatement("UPDATE `oc_ ... )", [ "*** sensi ... 0], [ 1,2,2,2,2])

    /var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php - line 281:

    Doctrine\DBAL\Query\QueryBuilder->execute()

    /var/www/html/lib/private/Files/Cache/Cache.php - line 382:

    OC\DB\QueryBuilder\QueryBuilder->execute()

    /var/www/html/lib/private/Files/Cache/Updater.php - line 256:

    OC\Files\Cache\Cache->update("*** sensiti ... *")

    /var/www/html/lib/private/Files/Cache/Updater.php - line 138:

    OC\Files\Cache\Updater->correctParentStorageMtime("*** sensiti ... *")

    /var/www/html/apps/dav/lib/Connector/Sabre/File.php - line 369:

    OC\Files\Cache\Updater->update("*** sensiti ... *")

    /var/www/html/apps/dav/lib/Connector/Sabre/Directory.php - line 164:

    OCA\DAV\Connector\Sabre\File->put(null)

    /var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php - line 1098:

    OCA\DAV\Connector\Sabre\Directory->createFile("MediaTest.php", null)

    /var/www/html/3rdparty/sabre/dav/lib/DAV/CorePlugin.php - line 504:

    Sabre\DAV\Server->createFile("__ Stellair ... p", null, null)

    /var/www/html/3rdparty/sabre/event/lib/WildcardEmitterTrait.php - line 89:

    Sabre\DAV\CorePlugin->httpPut(Sabre\HTTP\Request {}, Sabre\HTTP\Response {})

    /var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php - line 472:

    Sabre\DAV\Server->emit("method:PUT", [ Sabre\HTTP ... }])

    /var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php - line 253:

    Sabre\DAV\Server->invokeMethod(Sabre\HTTP\Request {}, Sabre\HTTP\Response {})

    /var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php - line 321:

    Sabre\DAV\Server->start()

    /var/www/html/apps/dav/appinfo/v1/webdav.php - line 83:

    Sabre\DAV\Server->exec()

    /var/www/html/remote.php - line 166:

    require_once("/var/www/ht ... p")

Caused by Doctrine\DBAL\Driver\PDO\Exception: SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction

    /var/www/html/3rdparty/doctrine/dbal/src/Driver/PDO/Statement.php - line 94:

    Doctrine\DBAL\Driver\PDO\Exception::new(PDOException ... ]})

    /var/www/html/3rdparty/doctrine/dbal/src/Connection.php - line 1163:

    Doctrine\DBAL\Driver\PDO\Statement->execute()

    /var/www/html/lib/private/DB/Connection.php - line 294:

    Doctrine\DBAL\Connection->executeStatement("UPDATE `oc_ ... )", [ 1656744470 ... 0], [ 2,2,1,2,2])

    /var/www/html/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php - line 354:

    OC\DB\Connection->executeStatement("UPDATE `oc_ ... )", [ "*** sensi ... 0], [ 1,2,2,2,2])

    /var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php - line 281:

    Doctrine\DBAL\Query\QueryBuilder->execute()

    /var/www/html/lib/private/Files/Cache/Cache.php - line 382:

    OC\DB\QueryBuilder\QueryBuilder->execute()

    /var/www/html/lib/private/Files/Cache/Updater.php - line 256:

    OC\Files\Cache\Cache->update("*** sensiti ... *")

    /var/www/html/lib/private/Files/Cache/Updater.php - line 138:

    OC\Files\Cache\Updater->correctParentStorageMtime("*** sensiti ... *")

    /var/www/html/apps/dav/lib/Connector/Sabre/File.php - line 369:

    OC\Files\Cache\Updater->update("*** sensiti ... *")

    /var/www/html/apps/dav/lib/Connector/Sabre/Directory.php - line 164:

    OCA\DAV\Connector\Sabre\File->put(null)

    /var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php - line 1098:

    OCA\DAV\Connector\Sabre\Directory->createFile("MediaTest.php", null)

    /var/www/html/3rdparty/sabre/dav/lib/DAV/CorePlugin.php - line 504:

    Sabre\DAV\Server->createFile("__ Stellair ... p", null, null)

    /var/www/html/3rdparty/sabre/event/lib/WildcardEmitterTrait.php - line 89:

    Sabre\DAV\CorePlugin->httpPut(Sabre\HTTP\Request {}, Sabre\HTTP\Response {})

    /var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php - line 472:

    Sabre\DAV\Server->emit("method:PUT", [ Sabre\HTTP ... }])

    /var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php - line 253:

    Sabre\DAV\Server->invokeMethod(Sabre\HTTP\Request {}, Sabre\HTTP\Response {})

    /var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php - line 321:

    Sabre\DAV\Server->start()

    /var/www/html/apps/dav/appinfo/v1/webdav.php - line 83:

    Sabre\DAV\Server->exec()

    /var/www/html/remote.php - line 166:

    require_once("/var/www/ht ... p")

Caused by PDOException: SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction

    /var/www/html/3rdparty/doctrine/dbal/src/Driver/PDO/Statement.php - line 92:

    PDOStatement->execute(null)

    /var/www/html/3rdparty/doctrine/dbal/src/Connection.php - line 1163:

    Doctrine\DBAL\Driver\PDO\Statement->execute()

    /var/www/html/lib/private/DB/Connection.php - line 294:

    Doctrine\DBAL\Connection->executeStatement("UPDATE `oc_ ... )", [ 1656744470 ... 0], [ 2,2,1,2,2])

    /var/www/html/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php - line 354:

    OC\DB\Connection->executeStatement("UPDATE `oc_ ... )", [ "*** sensi ... 0], [ 1,2,2,2,2])

    /var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php - line 281:

    Doctrine\DBAL\Query\QueryBuilder->execute()

    /var/www/html/lib/private/Files/Cache/Cache.php - line 382:

    OC\DB\QueryBuilder\QueryBuilder->execute()

    /var/www/html/lib/private/Files/Cache/Updater.php - line 256:

    OC\Files\Cache\Cache->update("*** sensiti ... *")

    /var/www/html/lib/private/Files/Cache/Updater.php - line 138:

    OC\Files\Cache\Updater->correctParentStorageMtime("*** sensiti ... *")

    /var/www/html/apps/dav/lib/Connector/Sabre/File.php - line 369:

    OC\Files\Cache\Updater->update("*** sensiti ... *")

    /var/www/html/apps/dav/lib/Connector/Sabre/Directory.php - line 164:

    OCA\DAV\Connector\Sabre\File->put(null)

    /var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php - line 1098:

    OCA\DAV\Connector\Sabre\Directory->createFile("MediaTest.php", null)

    /var/www/html/3rdparty/sabre/dav/lib/DAV/CorePlugin.php - line 504:

    Sabre\DAV\Server->createFile("__ Stellair ... p", null, null)

    /var/www/html/3rdparty/sabre/event/lib/WildcardEmitterTrait.php - line 89:

    Sabre\DAV\CorePlugin->httpPut(Sabre\HTTP\Request {}, Sabre\HTTP\Response {})

    /var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php - line 472:

    Sabre\DAV\Server->emit("method:PUT", [ Sabre\HTTP ... }])

    /var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php - line 253:

    Sabre\DAV\Server->invokeMethod(Sabre\HTTP\Request {}, Sabre\HTTP\Response {})

    /var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php - line 321:

    Sabre\DAV\Server->start()

    /var/www/html/apps/dav/appinfo/v1/webdav.php - line 83:

    Sabre\DAV\Server->exec()

    /var/www/html/remote.php - line 166:

    require_once("/var/www/ht ... p")

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


<?php
$CONFIG = array (
  'memcache.local' => '\\OC\\Memcache\\Redis',
  'apps_paths' =>
  array (
    0 =>
    array (
      'path' => '/var/www/html/apps',
      'url' => '/apps',
      'writable' => false,
    ),
    1 =>
    array (
      'path' => '/var/www/html/custom_apps',
      'url' => '/custom_apps',
      'writable' => true,
    ),
  ),
  'instanceid' => 'blabla',
  'passwordsalt' => 'blabla',
  'secret' => 'blabla',
  'trusted_domains' =>
  array (
    0 => 'blabla',
    1 => 'blabla',
  ),
  'datadirectory' => '/var/www/html/data',
  'dbtype' => 'mysql',
  'version' => '24.0.2.1',
  'overwrite.cli.url' => 'http://blabla:8080',
  'dbname' => 'nextcloud',
  'dbhost' => 'db',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextcloud',
  'dbpassword' => 'blabla',
  'installed' => true,
  'mail_from_address' => 'blabla',
  'mail_smtpmode' => 'smtp',
  'mail_sendmailmode' => 'smtp',
  'mail_domain' => 'blabla',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_smtpauth' => 1,
  'mail_smtphost' => 'blabla',
  'mail_smtpsecure' => 'tls',
  'mail_smtpname' => 'blabla',
  'mail_smtppassword' => 'blabla',
);

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

none (stdout)

PASTE HERE


Output errors in nextcloud.log in /var/www/ or as admin user in top right menu, filtering for errors. Use a pastebin service if necessary.

PASTE HERE

additional info:

Tried changing from acpu to redis in the config.php provides the same result.

This:

cat /usr/local/etc/php/conf.d/docker-php-ext-apcu.ini > /etc/php/8.0/cli/conf.d/20-apcu.ini

provides the same results.

root@eaa33c5d5061:/var/www/html# cat /usr/local/etc/php/conf.d/docker-php-ext-apcu.ini
extension=apcu
apc.enable_cli=1
root@eaa33c5d5061:/var/www/html# 

above check as indicated solution in similar issue does not fix it.

So, if it is caused by apcu configuration for occ cli, where can I fix that in a nextcloud:fpm container ?
Any workaround like moving to redis, or disabling the cach totally ?

Found the solution thanks to this issue explanations : Allowed memory size of xxx bytes exhausted in current latest-container · Issue #1413 · nextcloud/docker · GitHub

I replaced

sudo -u www-data  php ../occ help            

with

su -p www-data  -s /bin/sh -c '../occ app:enable notes'          

The reason was the memory limit of 512m was not passed from the environment without the -p flag, and fell down to default 2m.