Issue Bug Closed

#87993Uncaught TYPO3 Exception: Call to a member function getDatabase() on null

Robert Vock 03/25/19, 09:08 updated 05/07/19, 12:10

Description

I’ve got some random exceptions in my TYPO3 log:

Sun, 24 Mar 2019 04:01:57 +0100 [CRITICAL] request="" component="TYPO3.CMS.Core.Error.ProductionExceptionHandler": Core: Exception handler (WEB): Uncaught TYPO3 Exception: Call to a member function getDatabase() on null | Error thrown in file PATH/public/typo3/sysext/frontend/Classes/Middleware/TypoScriptFrontendInitialization.php in line 74. Requested URL: https://www.example.de/ - {"
TYPO3_MODE":"FE","exception":{}}

It appears they are generated in TypoScriptFrontendInitialization :

try {
    $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('pages');
    $connection->connect();
} catch (ConnectionException $exception) {
    // Cannot connect to current database
    $message = 'Cannot connect to the configured database "' . $connection->getDatabase() . '"';
    $this->logger->emergency($message, ['exception' => $exception]);
    try {
        return GeneralUtility::makeInstance(ErrorController::class)->unavailableAction($request, $message);
    } catch (ServiceUnavailableException $e) {
        throw new ServiceUnavailableException($message, 1526013723);
    }
}

The catch block tries to use the variable $connection, even though it might not be initialized if an exception occurred.

I believe the exception leading to the catch-block might be generated because some cronjobs are running and mysql is busy.

Reviews 2