PDO leak in PHP 8.1/Lumen/Postgres

27 Views Asked by At

We're running a series of test cases; our code is built on Lumen. Our PHP is 8.1.22, our database is PostgreSQL 11, and we're using Lumen 8.6 and PHPUnit 9.0 to run the tests.

When we run the tests, on some of our devs' machines, there are huge connection leaks and we end up with 341 concurrent connections. On other machines, there are no connection leaks, and the max concurrent connections is more like 10 or 11.

Our custom test-case base class looks like this:

abstract class TestCase extends \Laravel\Lumen\Testing\TestCase {
// ...
    public function tearDown(): void {
        // All kinds of issues were cropping up when using database transactions.
        // Ultimately forcing the database connection to close resolved all of them.
        // This should not interfere with the transactional support as
        // the closing of the connection should rollback the transaction automatically
        $this->app->make('db')->connection('tenant')->disconnect();
        // ...
        parent::tearDown();
        // ...
    }
// ...
}

The bits with ellipses handle other stuff, including some stuff that involves a legacy ZF1 database connection, but that's opened at most once so can't be the issue here.

The comments about transactions are not my doing; someone else wrote them.

What's going wrong?

0

There are 0 best solutions below