Bug #78982 [Opn->Csd]: pdo_pgsql returns dead persistent connection

From: Date: Fri, 20 Dec 2019 11:07:06 +0000
Subject: Bug #78982 [Opn->Csd]: pdo_pgsql returns dead persistent connection
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-224441@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 Updated by: nikic@php.net Reported by: kentaro at ranvis dot com Summary: pdo_pgsql returns dead persistent connection -Status: Open +Status: Closed Type: Bug Package: PDO PgSQL PHP Version: master-Git-2019-12-17 (Git) Block user comment: N Private report: N New Comment: Automatic comment on behalf of kentaro@ranvis.com Revision: http://git.php.net/?p=php-src.git;a=commit;h=37d11d123e4b8952bf973e372c4062f6d0a7bca8 Log: Fix #78982: pdo_pgsql returns dead persistent connection Previous Comments: ------------------------------------------------------------------------ [2019-12-17 17:40:28] kentaro at ranvis dot com 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 ------------------------------------------------------------------------ [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 (#224441) next »