Bug #65825 [Opn->Csd]: PDOStatement::fetch() does not throw exception on broken server connection

From: Date: Wed, 28 Oct 2020 16:19:10 +0000
Subject: Bug #65825 [Opn->Csd]: PDOStatement::fetch() does not throw exception on broken server connection
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-229990@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=65825&edit=1

 ID:                 65825
 Updated by:         nikic@php.net
 Reported by:        cf0hay at gmail dot com
 Summary:            PDOStatement::fetch() does not throw exception on
                     broken server connection
-Status:             Open
+Status:             Closed
 Type:               Bug
 Package:            PDO MySQL
 Operating System:   Hardened Gentoo Linux 64
 PHP Version:        5.5.4
 Block user comment: N
 Private report:     N

 New Comment:

Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=a66d73db4b2e2fcf03b9ecbbc196440eefeb6641
Log: Fixed bug #65825


Previous Comments:
------------------------------------------------------------------------
[2013-10-03 11:35:41] cf0hay at gmail dot com

The correct SQLSTATE would be HY000, 2013.

------------------------------------------------------------------------
[2013-10-03 11:15:25] cf0hay at gmail dot com

Description:
------------
Using PDO with mysqlnd driver.

PDO instance was asked to throw exceptions, but calling fetch() after the TCP connection broke does
not throw an exception, it just emits a warning instead, "Empty row packet body".

The server is located on a different computer on the network, cannot use unix socket to reach it.

Test script:
---------------
$conn = new PDO(
            'mysql:host=192.168.1.2;dbname=somedb;charset=utf8',
            'somedbuser',
            'somedbpass',
            array(
                PDO::ATTR_PERSISTENT => false,
                PDO::ATTR_EMULATE_PREPARES => false,
                PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
                PDO::ATTR_STRINGIFY_FETCHES => false,
                PDO::ATTR_AUTOCOMMIT => true,
                PDO::MYSQL_ATTR_INIT_COMMAND => "SET time_zone = '+00:00'",
                PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false,
                PDO::MYSQL_ATTR_DIRECT_QUERY => false,
                PDO::MYSQL_ATTR_FOUND_ROWS => false,
            )
        );

        $res = $conn->query("
            any query which gives back a lot of rows
        ");
        while($row = $res->fetch(PDO::FETCH_ASSOC)){
            //during this loop runs, terminate the connection with something, like iptables
            var_export($row);
        }
        var_export($row);


Expected result:
----------------
PDOStatement::fetch() should throw an exception as the server connection has gone away (trying to do
a new PDO::query() after does throw an exception with that error message).

Actual result:
--------------
The script above just emits a warning and finishes the loop returning false the very same way as if
there were no more rows left from the query.


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



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


Thread (3 messages)

« previous php.bugs (#229990) next »