From fb8857f1fe4b3619e18a2ee67ea274b7b4d73f59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Wed, 22 Sep 2021 16:39:31 +0200 Subject: [PATCH] Fix a bug in get_multiple_idle_connections() #3628 2.3.0 introduces a bug that prevents proxysql to run ping on backend connections to keep them alive. --- lib/MySQL_HostGroups_Manager.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/MySQL_HostGroups_Manager.cpp b/lib/MySQL_HostGroups_Manager.cpp index 21c64391c..7aa5f7e13 100644 --- a/lib/MySQL_HostGroups_Manager.cpp +++ b/lib/MySQL_HostGroups_Manager.cpp @@ -3548,8 +3548,22 @@ int MySQL_HostGroups_Manager::get_multiple_idle_connections(int _hid, unsigned l drop_all_idle_connections(); int num_conn_current=0; int j,k; - MyHGC* myhgc = MyHGC_find(_hid); - if (myhgc) { + MyHGC* myhgc = NULL; + for (int i=0; i<(int)MyHostGroups->len; i++) { + if (_hid == -1) { + // all hostgroups must be examined + // as of version 2.3.2 , this is always the case + myhgc=(MyHGC *)MyHostGroups->index(i); + } else { + // only one hostgroup is examined + // as of version 2.3.2 , this never happen + // but the code support this functionality + myhgc = MyHGC_find(_hid); + i = (int)MyHostGroups->len; // to exit from this "for" loop + if (myhgc == NULL) + continue; // immediately exit + } + if (_hid >= 0 && _hid!=(int)myhgc->hid) continue; for (j=0; j<(int)myhgc->mysrvs->cnt(); j++) { MySrvC *mysrvc=(MySrvC *)myhgc->mysrvs->servers->index(j); //PtrArray *pa=mysrvc->ConnectionsFree->conns;