From e3026cbc6f777712d3d04a593fac02c9f78ee79c Mon Sep 17 00:00:00 2001 From: Rene Cannao Date: Thu, 5 Feb 2026 15:19:38 +0000 Subject: [PATCH] Fix wrong index in connection cleanup loops (MySQL and PgSQL) This commit fixes a bug where connection cleanup loops were removing the wrong connection from the pool. The loops checked each connection by index (i), but when an expired connection was found, they removed index 0 instead of index i. This caused: - Fresh connections at index 0 to be incorrectly deleted - Expired connections to remain in the pool Fixed files: - lib/Base_HostGroups_Manager.cpp:2603 (MySQL) - lib/MySQL_HostGroups_Manager.cpp:2939 (MySQL) - lib/PgSQL_HostGroups_Manager.cpp:2782 (PgSQL) The fix changes `remove(0)` to `remove(i)` to remove the correct connection. Related: #5094 (fixes similar issue in drop_all_idle_connections) --- lib/Base_HostGroups_Manager.cpp | 2 +- lib/MySQL_HostGroups_Manager.cpp | 2 +- lib/PgSQL_HostGroups_Manager.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Base_HostGroups_Manager.cpp b/lib/Base_HostGroups_Manager.cpp index 734b94448..d35795156 100644 --- a/lib/Base_HostGroups_Manager.cpp +++ b/lib/Base_HostGroups_Manager.cpp @@ -2600,7 +2600,7 @@ void MySQL_HostGroups_Manager::drop_all_idle_connections() { unsigned long long intv = mysql_thread___connection_max_age_ms; intv *= 1000; if (curtime > mc->creation_time + intv) { - mc=mscl->remove(0); + mc=mscl->remove(i); delete mc; i--; } diff --git a/lib/MySQL_HostGroups_Manager.cpp b/lib/MySQL_HostGroups_Manager.cpp index ccb38fd2e..cf520ed50 100644 --- a/lib/MySQL_HostGroups_Manager.cpp +++ b/lib/MySQL_HostGroups_Manager.cpp @@ -2936,7 +2936,7 @@ void MySQL_HostGroups_Manager::drop_all_idle_connections() { unsigned long long intv = mysql_thread___connection_max_age_ms; intv *= 1000; if (curtime > mc->creation_time + intv) { - mc=mscl->remove(0); + mc=mscl->remove(i); delete mc; i--; } diff --git a/lib/PgSQL_HostGroups_Manager.cpp b/lib/PgSQL_HostGroups_Manager.cpp index f51c4a3bf..eb442a938 100644 --- a/lib/PgSQL_HostGroups_Manager.cpp +++ b/lib/PgSQL_HostGroups_Manager.cpp @@ -2779,7 +2779,7 @@ void PgSQL_HostGroups_Manager::drop_all_idle_connections() { unsigned long long intv = pgsql_thread___connection_max_age_ms; intv *= 1000; if (curtime > mc->creation_time + intv) { - mc=mscl->remove(0); + mc=mscl->remove(i); delete mc; i--; }