Bug #80412 [Com]: PHP-FPM : PDO / Broken Pipe when DBMS ends the connection

From: Date: Tue, 24 Nov 2020 23:23:09 +0000
Subject: Bug #80412 [Com]: PHP-FPM : PDO / Broken Pipe when DBMS ends the connection
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-230596@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80412&edit=1

 ID:                 80412
 Comment by:         heavy-traffic-website at yopmail dot com
 Reported by:        heavy-traffic-website at yopmail dot com
 Summary:            PHP-FPM : PDO / Broken Pipe when DBMS ends the
                     connection
 Status:             Open
 Type:               Bug
 Package:            PDO Core
 Operating System:   Debian 11
 PHP Version:        7.4.12
 Block user comment: N
 Private report:     N

 New Comment:

Thank you for your review.

The code PDO::__contruct() is very explicit : I want a persistent connection. And this line works
until the pipe exists.

Maybe not everybody use HAproxy between Galera Cluster and PHP-FPM but, the code to keep it working
without error is really poor :
try{ new PDO() }catch(){ new PDO() }  

Please don't justify this is normal, when the pipe broke whatever the reason is : PHP/PDO
should DETECT the broken PIPE and treat the __construct like no one persistent connection exists yet
inside each thead.

We are on the ends of 2020, it has to think logic and serve the langage, not saying like 10 year ago
: it is still a feature.


Previous Comments:
------------------------------------------------------------------------
[2020-11-24 23:06:36] daverandom@php.net

Note also that there is no implied re-connect on remote connection drop in any PHP-RDBMS drivers
(afaik). It is generally assumed that reconnection would be a thing that should be dealt with in
userland, as there is no universal strategy for interval, back-off or max retry count.

------------------------------------------------------------------------
[2020-11-24 23:03:25] daverandom@php.net

Note that this would be per-driver behaviour, specific to the RDBMS being used rather than a generic
PDO problem. Any further information on the RDBMS system/version affected would be useful -
obviously the DSN used with PDO indicates that MySQL is affected by this.

------------------------------------------------------------------------
[2020-11-24 23:00:16] heavy-traffic-website at yopmail dot com

Description:
------------
Related to this very old bug reported 10 years ago
=> https://bugs.php.net/bug.php?id=53287


(johannes@php.net) was wrong - the bug still exists and no one fixed it.
--> Please consider the bug onto the PHP side, not the DBMS side.

------------------------

new PDO("mysql:host=127.0.0.1;dbname=XXX", "XXX", "XXX", [
PDO::ATTR_PERSISTENT => true ]);

PHP-FPM have threads with broken persistent connections and SHOULD try to reconnect a new one
connection rather than CRASHING an exception in the case where send of 5 bytes failed with errno=32
Broken pipe appens in __construct.

Test script:
---------------
With php7.4-fpm, i have some threads and when i have a wide blank time between DBMS and PHP,
probably the timeout of the DBMS break the pipe (default: 8h), however PHP/PDO don't care and
throw an exception instead of making a new one connection, inside each thread alive.

Currently, I have to try{ new PDO() }catch(){ new PDO() } to be working without error, it sucks !

Expected result:
----------------
The PDO side CAN be patched, so this is a bug. It is expected that PDO will try to reconnect
silently if the case described appears, before lauching any exception. And if any exception has to
be launched, it will certainly will not be these one but the new connection exception.

Actual result:
--------------
Catched Exception :

PDO::__construct(): send of 5 bytes failed with errno=32 Broken pipe


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=80412&edit=1


Thread (13 messages)

« previous php.bugs (#230596) next »