Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some of AbstractPlatform inheritors are preventing \PDO disconnect #5

Closed
weierophinney opened this issue Dec 31, 2019 · 1 comment
Closed
Labels
Bug Something isn't working
Milestone

Comments

@weierophinney
Copy link
Member

Some of Zend\Db\Adapter\Platform\AbstractPlatform inheritors (Mysql, Oracle, Postgresql, Sqlite, SqlServer) holding the reference of \PDO object (even if DriverInterface passed into constructor, because quote methods are reassigning resource reference of connection to local variable resource). This causing problems when you using Platform class and want to disconnect the \PDO instance with disconnect method of the ConnectionInterface.

We found that problem when noticed ~40k+ TCP connections on 3306 port stucked in CLOSE_WAIT state after disconnecting and exec another php script and exit original script.

Code to reproduce the issue

        $testConnection = function() {
            $mypid = getmypid();
            $lsof = shell_exec("lsof -i -P -n | grep 3306 | grep $mypid");
            echo ($lsof === null ? 'no connection' : 'connection established') . PHP_EOL;
        };

        // take your adapter with mysql driver inside
        $db = self::$infrastructure->db();

        $testConnection();

        $db->getDriver()->getConnection()->connect();

        $testConnection();

        $db->getDriver()->getConnection()->disconnect();

        $testConnection();

        $db->getDriver()->getConnection()->connect();

        $testConnection();

        $db->getPlatform()->quoteValue('test');
        $db->getDriver()->getConnection()->disconnect();

        $testConnection(); // are still connected? yes :(

Expected results

Connection is disconnected even when using quoteValue method of platform object

Actual results

Connection established


Originally posted by @jadrovski at zendframework/zend-db#387

@knifefencer
Copy link

This bug is very critical for our app. Php daemons cannot release resources on restart because they cannot destroy the PDO object. Before we wrote the patch, we had to resort to very ugly solutions. Please consider integrating an existing pool-request.

@michalbundyra michalbundyra added the Bug Something isn't working label Jan 10, 2020
@michalbundyra michalbundyra added this to the 2.11.2 milestone Jan 14, 2020
michalbundyra added a commit that referenced this issue Jan 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants