Bug #71023 [Opn->Ver]: mysqlnd statistic wrap

From: Date: Thu, 05 Aug 2021 13:35:16 +0000
Subject: Bug #71023 [Opn->Ver]: mysqlnd statistic wrap
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-235614@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71023&edit=1 ID: 71023 Updated by: cmb@php.net Reported by: damian dot poole at netregistry dot com dot au Summary: mysqlnd statistic wrap -Status: Open +Status: Verified Type: Bug Package: MySQL related Operating System: Debian x86_64 PHP Version: 7.0.0 Block user comment: N Private report: N New Comment: 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> Previous Comments: ------------------------------------------------------------------------ [2015-12-04 05:41:06] 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" ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=71023&edit=1

« previous php.bugs (#235614) next »