Skip to content

SQLSTATE[08004] [1040] Too many connections in a batch of functional tests #37

Description

@papatti

PHPUnit tests fail after the first ~200 tests with SQLSTATE[08004] [1040] Too many connections.
Each api call will trigger a full Symfony boot sequence, including PropelBundle's boot function, which creates a new connection each time, until the limit is reached.

I assumed, that Propel's ConnectionManagerSingle should close existing connections when new configuration is provided (ConnectionManagerSingle::setConfiguration()) by detaching connection objects. If nobody uses them, objects are destroyed, connections are closed. But not...

In Propel1 there was a !\Propel::isInit() function, this was used in PropelBundle to avoid multiple connection instances, but this has been removed, and the Propel::init() is also deprecated.

I reported this problem for Propel guys, but no answer till now (propelorm/Propel2#1906).

I managed to avoid this problem by emulating Propel1's behaviour by having

    private static $isInitialized = false;

    /**
     * {@inheritdoc}
     */
    public function boot(): void
    {
        try {
            if (!self::$isInitialized) {
                $this->configureConnections();

                if ($this->container->getParameter('propel.logging')) {
                    $this->configureLogging();
                }

                self::$isInitialized = true;
            }
        } catch( \Exception $e ) {
        }
    }

in PropelBundle, but I'm not convinced that this is the correct solution.

(Symfony 5.4.18, PHP 8.0.24, MySQL 5.7, PHPUnit 9.3.11)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions