Mail app causes this error: SQLSTATE general error 2006: MySQL server has gone away

I receive the following error every 12hr when the mail app is enabled:

PDOException: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away in /var/www/html/3rdparty/doctrine/dbal/src/Driver/PDO/Statement.php:101
Stack trace:
#0 /var/www/html/3rdparty/doctrine/dbal/src/Driver/PDO/Statement.php(101): PDOStatement->execute(NULL)
#1 /var/www/html/3rdparty/doctrine/dbal/src/Connection.php(1153): Doctrine\DBAL\Driver\PDO\Statement->execute()
#2 /var/www/html/lib/private/DB/Connection.php(295): Doctrine\DBAL\Connection->executeStatement('UPDATE `oc_jobs...', Array, Array)
#3 /var/www/html/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php(354): OC\DB\Connection->executeStatement('UPDATE `oc_jobs...', Array, Array)
#4 /var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php(280): Doctrine\DBAL\Query\QueryBuilder->execute()
#5 /var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php(326): OC\DB\QueryBuilder\QueryBuilder->execute()
#6 /var/www/html/lib/private/BackgroundJob/JobList.php(360): OC\DB\QueryBuilder\QueryBuilder->executeStatement()
#7 /var/www/html/lib/private/BackgroundJob/JobList.php(348): OC\BackgroundJob\JobList->unlockJob(Object(OCA\Mail\BackgroundJob\PreviewEnhancementProcessingJob))
#8 /var/www/html/cron.php(158): OC\BackgroundJob\JobList->setLastJob(Object(OCA\Mail\BackgroundJob\PreviewEnhancementProcessingJob))
#9 {main}

Next Doctrine\DBAL\Driver\PDO\Exception: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away in /var/www/html/3rdparty/doctrine/dbal/src/Driver/PDO/Exception.php:30
Stack trace:
#0 /var/www/html/3rdparty/doctrine/dbal/src/Driver/PDO/Statement.php(103): Doctrine\DBAL\Driver\PDO\Exception::new(Object(PDOException))
#1 /var/www/html/3rdparty/doctrine/dbal/src/Connection.php(1153): Doctrine\DBAL\Driver\PDO\Statement->execute()
#2 /var/www/html/lib/private/DB/Connection.php(295): Doctrine\DBAL\Connection->executeStatement('UPDATE `oc_jobs...', Array, Array)
#3 /var/www/html/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php(354): OC\DB\Connection->executeStatement('UPDATE `oc_jobs...', Array, Array)
#4 /var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php(280): Doctrine\DBAL\Query\QueryBuilder->execute()
#5 /var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php(326): OC\DB\QueryBuilder\QueryBuilder->execute()
#6 /var/www/html/lib/private/BackgroundJob/JobList.php(360): OC\DB\QueryBuilder\QueryBuilder->executeStatement()
#7 /var/www/html/lib/private/BackgroundJob/JobList.php(348): OC\BackgroundJob\JobList->unlockJob(Object(OCA\Mail\BackgroundJob\PreviewEnhancementProcessingJob))
#8 /var/www/html/cron.php(158): OC\BackgroundJob\JobList->setLastJob(Object(OCA\Mail\BackgroundJob\PreviewEnhancementProcessingJob))
#9 {main}

Next Doctrine\DBAL\Exception\ConnectionLost: An exception occurred while executing a query: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away in /var/www/html/3rdparty/doctrine/dbal/src/Driver/API/MySQL/ExceptionConverter.php:106
Stack trace:
#0 /var/www/html/3rdparty/doctrine/dbal/src/Connection.php(1814): Doctrine\DBAL\Driver\API\MySQL\ExceptionConverter->convert(Object(Doctrine\DBAL\Driver\PDO\Exception), Object(Doctrine\DBAL\Query))
#1 /var/www/html/3rdparty/doctrine/dbal/src/Connection.php(1749): Doctrine\DBAL\Connection->handleDriverException(Object(Doctrine\DBAL\Driver\PDO\Exception), Object(Doctrine\DBAL\Query))
#2 /var/www/html/3rdparty/doctrine/dbal/src/Connection.php(1163): Doctrine\DBAL\Connection->convertExceptionDuringQuery(Object(Doctrine\DBAL\Driver\PDO\Exception), 'UPDATE `oc_jobs...', Array, Array)
#3 /var/www/html/lib/private/DB/Connection.php(295): Doctrine\DBAL\Connection->executeStatement('UPDATE `oc_jobs...', Array, Array)
#4 /var/www/html/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php(354): OC\DB\Connection->executeStatement('UPDATE `oc_jobs...', Array, Array)
#5 /var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php(280): Doctrine\DBAL\Query\QueryBuilder->execute()
#6 /var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php(326): OC\DB\QueryBuilder\QueryBuilder->execute()
#7 /var/www/html/lib/private/BackgroundJob/JobList.php(360): OC\DB\QueryBuilder\QueryBuilder->executeStatement()
#8 /var/www/html/lib/private/BackgroundJob/JobList.php(348): OC\BackgroundJob\JobList->unlockJob(Object(OCA\Mail\BackgroundJob\PreviewEnhancementProcessingJob))
#9 /var/www/html/cron.php(158): OC\BackgroundJob\JobList->setLastJob(Object(OCA\Mail\BackgroundJob\PreviewEnhancementProcessingJob))
#10 {main}

Next OC\DB\Exceptions\DbalException: An exception occurred while executing a query: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away in /var/www/html/lib/private/DB/Exceptions/DbalException.php:71
Stack trace:
#0 /var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php(328): OC\DB\Exceptions\DbalException::wrap(Object(Doctrine\DBAL\Exception\ConnectionLost))
#1 /var/www/html/lib/private/BackgroundJob/JobList.php(360): OC\DB\QueryBuilder\QueryBuilder->executeStatement()
#2 /var/www/html/lib/private/BackgroundJob/JobList.php(348): OC\BackgroundJob\JobList->unlockJob(Object(OCA\Mail\BackgroundJob\PreviewEnhancementProcessingJob))
#3 /var/www/html/cron.php(158): OC\BackgroundJob\JobList->setLastJob(Object(OCA\Mail\BackgroundJob\PreviewEnhancementProcessingJob))
#4 {main}

The mail app seems to work OK at first sight.

What could cause this error?

My installation:

  • NC 27.1.2
  • mariadb 10.6.1
  • installed with docker on debian 11

In that case you should increase max_allowed_packet in the [mysqld] section of your database configuration file.

In my setup it is 1 GB, the default is 16 MB.
Alter it in litle steps, (begin with e.g. 64MB) until that message dissapears.

You can display the size of that variable in your database with the following query:

SHOW VARIABLES LIKE 'max_allowed_packet';

Much luck,
ernolf

It could also be the wait_timeout that needs to be adjusted additionally, see Database configuration — Nextcloud latest Administration Manual latest documentation

1 Like

It is true that this is written in the manual, but since the default value of wait_timeout variable on mariadb is 8 hours, it has no meaning in practice, since in practically every Nextcloud instance the database is constantly accessed, just through the regular cron jobs.

So it’s basically just the max_allowed_packet variable that is important to fix this problem.

Much luck,
ernolf

1 Like

Oh, I did not know, thanks for letting me know. I agree, 8 hours should probably be high enough :joy:

1 Like

Thanks for the tip. I’ve changed it to 128MB and so far I didn’t receive this error again (after I’ve changed it to 64MB and disabled/re-enabled the mail app I received one after a few minutes).
I’ll wait a day to see if the situation stays like that.

FYI: upon enabling the mail app in the webgui, I also received a timeout error. Enabling it through the OCC command did work flawlessly but it took a long time (I’m running Nextcloud on a SBC so some operations are slow).
Maybe this error is related to it.

We"re now 2 days later and I haven’t received any mysql errors anymore. Seems this was indeed the culprint!

Thanks for your help.