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)
pull/5344/head
Rene Cannao 3 months ago
parent 8e58ce592f
commit e3026cbc6f

@ -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--;
}

@ -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--;
}

@ -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--;
}

Loading…
Cancel
Save