diff -u b/core/modules/dblog/src/Logger/DbLog.php b/core/modules/dblog/src/Logger/DbLog.php --- b/core/modules/dblog/src/Logger/DbLog.php +++ b/core/modules/dblog/src/Logger/DbLog.php @@ -84,12 +84,23 @@ ->execute(); } catch (\Exception $e) { + // When running Drupal on MySQL or Maria DB you can run in several errors + // that corrupt the database connection. Some examples for these kind of + // errors on the database layer are "1100 - Table 'xyz' was not locked + // with LOCK TABLES" and "1153 – Got a packet bigger than + // ‘max_allowed_packet’ bytes". If such an error happens, the MySQL server + // invalidates the connection and answers all further request through this + // connection by "2006 - MySQL server had gone away". In that case the + // insert statement above results in a database exception. To ensure that + // the causal error is written to the log we try once to open a dedicated + // connection and write again. if ( + // Only handle database related exceptions. ($e instanceof DatabaseException || $e instanceof \PDOException) && + // Avoid an endless loop of re-write attempts. $this->connection->getTarget() != self::DEDICATED_DBLOG_CONNECTION_TARGET ) { - // Open a dedicated connection for logging to ensure that errors that - // messed up the default connection are still logged. + // Open a dedicated connection for logging. $key = $this->connection->getKey(); $info = Database::getConnectionInfo($key); Database::addConnectionInfo($key, self::DEDICATED_DBLOG_CONNECTION_TARGET, $info['default']);