php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71023 mysqlnd statistic wrap
Submitted: 2015-12-04 05:41 UTC Modified: 2021-08-05 13:35 UTC
Votes:5
Avg. Score:3.8 ± 1.0
Reproduced:4 of 5 (80.0%)
Same Version:1 (25.0%)
Same OS:0 (0.0%)
From: damian dot poole at netregistry dot com dot au Assigned:
Status: Verified Package: MySQL related
PHP Version: 7.0.0 OS: Debian x86_64
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: damian dot poole at netregistry dot com dot au
New email:
PHP Version: OS:

 

 [2015-12-04 05:41 UTC] damian dot poole at netregistry dot com dot au
Description:
------------
Some of the connection statistics for the MySQL native driver (namely active_connections/ active persistent connections) can decrement past zero causing the statistic to wrap around to the max value of the type.

The attached patch fixes it for us as it stops the macros which increment/decrement from wrapping around.

Test script:
---------------
<?php
$mysqli = mysqli_init();
$mysqli->real_connect('1.2.3.4'); //non existant server
$stats = mysqli_get_client_stats();
var_dump($stats['active_connections']);

Expected result:
----------------
Warning: mysqli::real_connect(): (HY000/2002): Connection refused in /websites/ph/php70.damo.id.au/mysql.php on line 3
string(2) "0"

--- next run ---
Warning: mysqli::real_connect(): (HY000/2002): Connection refused in /websites/ph/php70.damo.id.au/mysql.php on line 3
string(2) "0"

Actual result:
--------------
Warning: mysqli::real_connect(): (HY000/2002): Connection refused in /websites/ph/php70.damo.id.au/mysql.php on line 3
string(20) "18446744073709551615"

--- next run ---
Warning: mysqli::real_connect(): (HY000/2002): Connection refused in /websites/ph/php70.damo.id.au/mysql.php on line 3
string(20) "18446744073709551614"

Patches

dpoole-nowrap-for-mysqlnd-uint64-decrement-or-increment (last revision 2015-12-04 05:46 UTC by damian dot poole at netregistry dot com dot au)
dpoole-nowrap-for-mysqlnd-uint64 (last revision 2015-12-04 05:41 UTC by damian dot poole at netregistry dot com dot au)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-08-05 13:35 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2021-08-05 13:35 UTC] cmb@php.net
I can confirm the erroneous behavior.  Thank you for the patch;
however, it doesn't look quite right to me.  What happens if there
is one connection open, and someone attempts to connect to a
non-existing server?  Wouldn't the active_connections be reported
as 0 afterwards?

I think the proper fix is to *not* decrease the active_connections
in case of connection failure[1], i.e. when state ==
CONN_QUIT_SENT.

However, I do not really understand the _s != _p_s->count
condition in MYSQLND_DEC_STATISTIC[2] and MYSQLND_INC_STATISTIC.
_s is an enum value; why would it match a count?

[1] <https://github.com/php/php-src/blob/php-7.4.22/ext/mysqlnd/mysqlnd_connection.c#L1235>
[2] <https://github.com/php/php-src/blob/php-7.4.22/ext/mysqlnd/mysqlnd_statistics.h#L58>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 11:01:28 2024 UTC