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
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
Expected results
Connection is disconnected even when using quoteValue method of platform object
Actual results
Connection established