Project

General

Profile

Actions

Bug #87993

closed

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

Added by Robert Vock over 5 years ago. Updated over 5 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Database API (Doctrine DBAL)
Target version:
-
Start date:
2019-03-25
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
9
PHP Version:
7.2
Tags:
Complexity:
Is Regression:
Sprint Focus:

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.

Actions #1

Updated by Benni Mack over 5 years ago

Hi Rob,

can you send us some more information on what's inside the caught Exception actually? Type, message, exception code.

Actions #2

Updated by Robert Vock over 5 years ago

At the moment: No, because I only have the Log-Entry of the uncatched-exception which is generated in the catch-block. But I've adjusted the code for our live project and will get back, when the error occurs the next time.

But it's easy to force this issue: Just change the database password to an incorrect password in LocalConfiguration.php. The next request will generate the above exception.
In that case, the ConnectionException has Code 0, and message "An exception occurred in driver: Access denied for user 'mysqluser'@'localhost' (using password: YES)"

Actions #3

Updated by Robert Vock over 5 years ago

I've adjusted the code which generates the message:

$message = 'Cannot connect to the configured database';

Now I get a better exception in the log. It indicates, that the MySQL Server is down (which you cannot guess based on the initial exception).

Fri, 29 Mar 2019 04:13:41 +0100 [EMERGENCY] request="c44736868e9aa" component="TYPO3.CMS.Frontend.Middleware.TypoScriptFrontendInitialization": Cannot connect to the configured database - {"exception":"Doctrine\DBAL\Driver\Mysqli\MysqliException: Connection refused in WEBSITEPATH/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php:86
Stack trace:
#0 WEBSITEPATH/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/Mysqli/Driver.php(36): Doctrine\DBAL\Driver\Mysqli\MysqliConnection->__construct(Array, 'DATABASE', 'PASSWORD', Array)
#1 WEBSITEPATH/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(389): Doctrine\DBAL\Driver\Mysqli\Driver->connect(Array, 'DATABASE', 'PASSWORD', Array)
#2 WEBSITEPATH/public/typo3/sysext/core/Classes/Database/Connection.php(93): Doctrine\DBAL\Connection->connect()
#3 WEBSITEPATH/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(453): TYPO3\CMS\Core\Database\Connection->connect()
#4 WEBSITEPATH/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(413): Doctrine\DBAL\Connection->getDatabasePlatformVersion()
#5 WEBSITEPATH/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(357): Doctrine\DBAL\Connection->detectDatabasePlatform()
#6 WEBSITEPATH/public/typo3/sysext/core/Classes/Database/ConnectionPool.php(166): Doctrine\DBAL\Connection->getDatabasePlatform()
#7 WEBSITEPATH/public/typo3/sysext/core/Classes/Database/ConnectionPool.php(128): TYPO3\CMS\Core\Database\ConnectionPool->getDatabaseConnection(Array)
#8 WEBSITEPATH/public/typo3/sysext/core/Classes/Database/ConnectionPool.php(82): TYPO3\CMS\Core\Database\ConnectionPool->getConnectionByName('Default')
#9 WEBSITEPATH/public/typo3/sysext/frontend/Classes/Middleware/TypoScriptFrontendInitialization.php(70): TYPO3\CMS\Core\Database\ConnectionPool->getConnectionForTable('pages')
#10 WEBSITEPATH/public/typo3/sysext/core/Classes/Http/MiddlewareDispatcher.php(138): TYPO3\CMS\Frontend\Middleware\TypoScriptFrontendInitialization->process(Object(TYPO3\CMS\Core\Http\ServerRequest), Object(class@anonymous))
#11 WEBSITEPATH/public/typo3/sysext/frontend/Classes/Middleware/EidHandler.php(50): class@anonymous->handle(Object(TYPO3\CMS\Core\Http\ServerRequest))
#12 WEBSITEPATH/public/typo3/sysext/core/Classes/Http/MiddlewareDispatcher.php(138): TYPO3\CMS\Frontend\Middleware\EidHandler->process(Object(TYPO3\CMS\Core\Http\ServerRequest), Object(class@anonymous))
#13 WEBSITEPATH/public/typo3/sysext/frontend/Classes/Middleware/PreprocessRequestHook.php(57): class@anonymous->handle(Object(TYPO3\CMS\Core\Http\ServerRequest))
#14 WEBSITEPATH/public/typo3/sysext/core/Classes/Http/MiddlewareDispatcher.php(138): TYPO3\CMS\Frontend\Middleware\PreprocessRequestHook->process(Object(TYPO3\CMS\Core\Http\ServerRequest), Object(class@anonymous))
#15 WEBSITEPATH/public/typo3/sysext/core/Classes/Middleware/NormalizedParamsAttribute.php(58): class@anonymous->handle(Object(TYPO3\CMS\Core\Http\ServerRequest))
#16 WEBSITEPATH/public/typo3/sysext/core/Classes/Http/MiddlewareDispatcher.php(138): TYPO3\CMS\Core\Middleware\NormalizedParamsAttribute->process(Object(TYPO3\CMS\Core\Http\ServerRequest), Object(class@anonymous))
#17 WEBSITEPATH/public/typo3/sysext/frontend/Classes/Middleware/TimeTrackerInitialization.php(49): class@anonymous->handle(Object(TYPO3\CMS\Core\Http\ServerRequest))
#18 WEBSITEPATH/public/typo3/sysext/core/Classes/Http/MiddlewareDispatcher.php(138): TYPO3\CMS\Frontend\Middleware\TimeTrackerInitialization->process(Object(TYPO3\CMS\Core\Http\ServerRequest), Object(class@anonymous))
#19 WEBSITEPATH/public/typo3/sysext/core/Classes/Http/MiddlewareDispatcher.php(67): class@anonymous->handle(Object(TYPO3\CMS\Core\Http\ServerRequest))
#20 WEBSITEPATH/public/typo3/sysext/core/Classes/Http/AbstractApplication.php(98): TYPO3\CMS\Core\Http\MiddlewareDispatcher->handle(Object(TYPO3\CMS\Core\Http\ServerRequest))
#21 WEBSITEPATH/public/typo3/sysext/frontend/Classes/Http/Application.php(69): TYPO3\CMS\Core\Http\AbstractApplication->handle(Object(TYPO3\CMS\Core\Http\ServerRequest))
#22 WEBSITEPATH/public/typo3/sysext/core/Classes/Http/AbstractApplication.php(110): TYPO3\CMS\Frontend\Http\Application->handle(Object(TYPO3\CMS\Core\Http\ServerRequest))
#23 WEBSITEPATH/public/index.php(24): TYPO3\CMS\Core\Http\AbstractApplication->run()
#24 WEBSITEPATH/public/index.php(25): {closure}()
#25 {main}

Next Doctrine\DBAL\Exception\ConnectionException: An exception occurred in driver: Connection refused in WEBSITEPATH/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:113
Stack trace:
#0 WEBSITEPATH/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php(184): Doctrine\DBAL\Driver\AbstractMySQLDriver->convertException('An exception oc...', Object(Doctrine\DBAL\Driver\Mysqli\MysqliException))
#1 WEBSITEPATH/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php(169): Doctrine\DBAL\DBALException::wrapException(Object(Doctrine\DBAL\Driver\Mysqli\Driver), Object(Doctrine\DBAL\Driver\Mysqli\MysqliException), 'An exception oc...')
#2 WEBSITEPATH/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/Mysqli/Driver.php(38): Doctrine\DBAL\DBALException::driverException(Object(Doctrine\DBAL\Driver\Mysqli\Driver), Object(Doctrine\DBAL\Driver\Mysqli\MysqliException))
#3 WEBSITEPATH/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(389): Doctrine\DBAL\Driver\Mysqli\Driver->connect(Array, 'DATABASE', 'PASSWORD', Array)
#4 WEBSITEPATH/public/typo3/sysext/core/Classes/Database/Connection.php(93): Doctrine\DBAL\Connection->connect()
#5 WEBSITEPATH/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(453): TYPO3\CMS\Core\Database\Connection->connect()
#6 WEBSITEPATH/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(413): Doctrine\DBAL\Connection->getDatabasePlatformVersion()
#7 WEBSITEPATH/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(357): Doctrine\DBAL\Connection->detectDatabasePlatform()
#8 WEBSITEPATH/public/typo3/sysext/core/Classes/Database/ConnectionPool.php(166): Doctrine\DBAL\Connection->getDatabasePlatform()
#9 WEBSITEPATH/public/typo3/sysext/core/Classes/Database/ConnectionPool.php(128): TYPO3\CMS\Core\Database\ConnectionPool->getDatabaseConnection(Array)
#10 WEBSITEPATH/public/typo3/sysext/core/Classes/Database/ConnectionPool.php(82): TYPO3\CMS\Core\Database\ConnectionPool->getConnectionByName('Default')
#11 WEBSITEPATH/public/typo3/sysext/frontend/Classes/Middleware/TypoScriptFrontendInitialization.php(70): TYPO3\CMS\Core\Database\ConnectionPool->getConnectionForTable('pages')
#12 WEBSITEPATH/public/typo3/sysext/core/Classes/Http/MiddlewareDispatcher.php(138): TYPO3\CMS\Frontend\Middleware\TypoScriptFrontendInitialization->process(Object(TYPO3\CMS\Core\Http\ServerRequest), Object(class@anonymous))
#13 WEBSITEPATH/public/typo3/sysext/frontend/Classes/Middleware/EidHandler.php(50): class@anonymous->handle(Object(TYPO3\CMS\Core\Http\ServerRequest))
#14 WEBSITEPATH/public/typo3/sysext/core/Classes/Http/MiddlewareDispatcher.php(138): TYPO3\CMS\Frontend\Middleware\EidHandler->process(Object(TYPO3\CMS\Core\Http\ServerRequest), Object(class@anonymous))
#15 WEBSITEPATH/public/typo3/sysext/frontend/Classes/Middleware/PreprocessRequestHook.php(57): class@anonymous->handle(Object(TYPO3\CMS\Core\Http\ServerRequest))
#16 WEBSITEPATH/public/typo3/sysext/core/Classes/Http/MiddlewareDispatcher.php(138): TYPO3\CMS\Frontend\Middleware\PreprocessRequestHook->process(Object(TYPO3\CMS\Core\Http\ServerRequest), Object(class@anonymous))
#17 WEBSITEPATH/public/typo3/sysext/core/Classes/Middleware/NormalizedParamsAttribute.php(58): class@anonymous->handle(Object(TYPO3\CMS\Core\Http\ServerRequest))
#18 WEBSITEPATH/public/typo3/sysext/core/Classes/Http/MiddlewareDispatcher.php(138): TYPO3\CMS\Core\Middleware\NormalizedParamsAttribute->process(Object(TYPO3\CMS\Core\Http\ServerRequest), Object(class@anonymous))
#19 WEBSITEPATH/public/typo3/sysext/frontend/Classes/Middleware/TimeTrackerInitialization.php(49): class@anonymous->handle(Object(TYPO3\CMS\Core\Http\ServerRequest))
#20 WEBSITEPATH/public/typo3/sysext/core/Classes/Http/MiddlewareDispatcher.php(138): TYPO3\CMS\Frontend\Middleware\TimeTrackerInitialization->process(Object(TYPO3\CMS\Core\Http\ServerRequest), Object(class@anonymous))
#21 WEBSITEPATH/public/typo3/sysext/core/Classes/Http/MiddlewareDispatcher.php(67): class@anonymous->handle(Object(TYPO3\CMS\Core\Http\ServerRequest))
#22 WEBSITEPATH/public/typo3/sysext/core/Classes/Http/AbstractApplication.php(98): TYPO3\CMS\Core\Http\MiddlewareDispatcher->handle(Object(TYPO3\CMS\Core\Http\ServerRequest))
#23 WEBSITEPATH/public/typo3/sysext/frontend/Classes/Http/Application.php(69): TYPO3\CMS\Core\Http\AbstractApplication->handle(Object(TYPO3\CMS\Core\Http\ServerRequest))
#24 WEBSITEPATH/public/typo3/sysext/core/Classes/Http/AbstractApplication.php(110): TYPO3\CMS\Frontend\Http\Application->handle(Object(TYPO3\CMS\Core\Http\ServerRequest))
#25 WEBSITEPATH/public/index.php(24): TYPO3\CMS\Core\Http\AbstractApplication->run()
#26 WEBSITEPATH/public/index.php(25): {closure}()
#27 {main}"}
Actions #4

Updated by Gerrit Code Review over 5 years ago

  • Status changed from New to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/60421

Actions #5

Updated by Gerrit Code Review over 5 years ago

Patch set 1 for branch 9.5 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/60439

Actions #6

Updated by Benni Mack over 5 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #7

Updated by Benni Mack over 5 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF