Skip to content

[Messenger] Break application if the database is not UP #37069

Closed
@lyrixx

Description

@lyrixx

Symfony version(s) affected: 5.1.0

Description

When symfony boot (CLI), the messenger stack is instanciated. And so the transports are instanciated. Then the doctrine transport tries to connect to the DB. And if there are no DB (in CI for example) it crashs !

It was not the case in 4.4.*

We have the following code:

if ($useNotify && ($wrappedConnection = $driverConnection->getWrappedConnection()) && method_exists($wrappedConnection, 'pgsqlGetNotify')) {
$connection = new PostgreSqlConnection($configuration, $driverConnection);
} else {
$connection = new Connection($configuration, $driverConnection);
}

This part of the code $driverConnection->getWrappedConnection() calls
https://github.com/doctrine/dbal/blob/18a053ad016207a66937f78f367f900c771aed94/lib/Doctrine/DBAL/Connection.php#L1455-L1460

And so the connection is established. So if the DB server is not available, it crashed.

In my case, it occrus during PHPStan test suite. In that case, we don't have a DB setup'ed so it does not works.

BTW, it occurs on every single command because messenger try load theses information when symfony boot 😬

Here is the full stack trace:

In PDOConnection.php line 27:
                                                                                               
  [PDOException]                                                                               
  PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known  
                                                                                               

Exception trace:
  at /home/circleci/redirection.io/server/backend/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:27
 PDO->__construct() at /home/circleci/redirection.io/server/backend/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:27
 Doctrine\DBAL\Driver\PDOConnection->__construct() at /home/circleci/redirection.io/server/backend/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php:22
 Doctrine\DBAL\Driver\PDOMySql\Driver->connect() at /home/circleci/redirection.io/server/backend/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:362
 Doctrine\DBAL\Connection->connect() at /home/circleci/redirection.io/server/backend/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:1449
 Doctrine\DBAL\Connection->getWrappedConnection() at /home/circleci/redirection.io/server/backend/vendor/symfony/symfony/src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/DoctrineTransportFactory.php:50
 Symfony\Component\Messenger\Bridge\Doctrine\Transport\DoctrineTransportFactory->createTransport() at /home/circleci/redirection.io/server/backend/vendor/symfony/symfony/src/Symfony/Component/Messenger/Transport/TransportFactory.php:36
 Symfony\Component\Messenger\Transport\TransportFactory->createTransport() at /home/circleci/redirection.io/server/backend/var/cache/dev/ContainerXfUbn4u/AppKernelDevDebugContainer.php:14822
 ContainerXfUbn4u\AppKernelDevDebugContainer->getMessenger_Transport_FailedService() at /home/circleci/redirection.io/server/backend/var/cache/dev/ContainerXfUbn4u/AppKernelDevDebugContainer.php:11684
 ContainerXfUbn4u\AppKernelDevDebugContainer->getConsole_Command_MessengerFailedMessagesRetryService() at /home/circleci/redirection.io/server/backend/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:441
 Symfony\Component\DependencyInjection\Container->getService() at /home/circleci/redirection.io/server/backend/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Argument/ServiceLocator.php:40
 Symfony\Component\DependencyInjection\Argument\ServiceLocator->get() at /home/circleci/redirection.io/server/backend/vendor/symfony/symfony/src/Symfony/Component/Console/CommandLoader/ContainerCommandLoader.php:45
 Symfony\Component\Console\CommandLoader\ContainerCommandLoader->get() at /home/circleci/redirection.io/server/backend/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:520
 Symfony\Component\Console\Application->has() at /home/circleci/redirection.io/server/backend/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:716
 Symfony\Component\Console\Application->all() at /home/circleci/redirection.io/server/backend/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:142
 Symfony\Bundle\FrameworkBundle\Console\Application->all() at /home/circleci/redirection.io/server/backend/vendor/symfony/symfony/src/Symfony/Component/Console/Descriptor/ApplicationDescription.php:91
 Symfony\Component\Console\Descriptor\ApplicationDescription->inspectApplication() at /home/circleci/redirection.io/server/backend/vendor/symfony/symfony/src/Symfony/Component/Console/Descriptor/ApplicationDescription.php:68
 Symfony\Component\Console\Descriptor\ApplicationDescription->getCommands() at /home/circleci/redirection.io/server/backend/vendor/symfony/symfony/src/Symfony/Component/Console/Descriptor/TextDescriptor.php:202
 Symfony\Component\Console\Descriptor\TextDescriptor->describeApplication() at /home/circleci/redirection.io/server/backend/vendor/symfony/symfony/src/Symfony/Component/Console/Descriptor/Descriptor.php:55
 Symfony\Component\Console\Descriptor\Descriptor->describe() at /home/circleci/redirection.io/server/backend/vendor/symfony/symfony/src/Symfony/Component/Console/Helper/DescriptorHelper.php:65
 Symfony\Component\Console\Helper\DescriptorHelper->describe() at /home/circleci/redirection.io/server/backend/vendor/symfony/symfony/src/Symfony/Component/Console/Command/ListCommand.php:75
 Symfony\Component\Console\Command\ListCommand->execute() at /home/circleci/redirection.io/server/backend/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:258
 Symfony\Component\Console\Command\Command->run() at /home/circleci/redirection.io/server/backend/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:929
 Symfony\Component\Console\Application->doRunCommand() at /home/circleci/redirection.io/server/backend/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:99
 Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /home/circleci/redirection.io/server/backend/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:264
 Symfony\Component\Console\Application->doRun() at /home/circleci/redirection.io/server/backend/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:82
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /home/circleci/redirection.io/server/backend/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:140
 Symfony\Component\Console\Application->run() at /home/circleci/redirection.io/server/backend/bin/console:29

list [--raw] [--format FORMAT] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] [<command> [<namespace>]]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions