php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78982 pdo_pgsql returns dead persistent connection
Submitted: 2019-12-17 17:38 UTC Modified: -
From: kentaro at ranvis dot com Assigned:
Status: Closed Package: PDO PgSQL
PHP Version: master-Git-2019-12-17 (Git) OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
6 - 1 = ?
Subscribe to this entry?

 
 [2019-12-17 17:38 UTC] 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

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-12-17 17:40 UTC] 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-20 11:07 UTC] nikic@php.net
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
 [2019-12-20 11:07 UTC] nikic@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 15:01:28 2024 UTC