Bug #78982 [PATCH]: pdo_pgsql returns dead persistent connection

From: Date: Tue, 17 Dec 2019 17:40:28 +0000
Subject: Bug #78982 [PATCH]: pdo_pgsql returns dead persistent connection
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-224364@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78982&edit=1 ID: 78982 Patch added by: kentaro@ranvis.com Reported by: kentaro at ranvis dot com Summary: pdo_pgsql returns dead persistent connection Status: Open Type: Bug Package: PDO PgSQL PHP Version: master-Git-2019-12-17 (Git) Block user comment: N Private report: N New Comment: The following pull request has been associated: Patch Name: Fix #78982: pdo_pgsql returns dead persistent connection On GitHub: https://github.com/php/php-src/pull/5021 Patch: https://github.com/php/php-src/pull/5021.patch Previous Comments: ------------------------------------------------------------------------ [2019-12-17 17:38:49] kentaro at ranvis dot com Description: ------------ When PDO::ATTR_PERSISTENT is true, PDO tells a driver to check if the connection is still alive. For PDO PgSQL driver, this is done in pdo_pgsql_check_liveness(). It calls PQstatus() to see if the status is good, but since PQstatus() only returns the previous status stored locally, the driver cannot tell if the connection is actually alive. This results in returning possible dead connection to the script. will add a PR. Test script: --------------- <?php $connArgs = ['pgsql:dbname=DB_NAME', 'USER', 'PASSWORD', [ PDO::ATTR_PERSISTENT => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, ]]; $pdo = new PDO(...$connArgs); var_dump($pdo->query('select 1')); $pdo = null; sleep(15); // kill the DB connection here //system('sudo systemctl restart postgresql-12'); //system('net stop postgresql-x64-12 && net start postgresql-x64-12'); $pdo = new PDO(...$connArgs); var_dump($pdo->query('select 1')); // should not throw but throws Expected result: ---------------- outputs 1 two times Actual result: -------------- outputs 1 then throws an exception ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=78982&edit=1

« previous php.bugs (#224364) next »