Skip to content

Commit

Permalink
Merge pull request #4546 from sysown/v2.x-fix_cluster_leaks
Browse files Browse the repository at this point in the history
Fix several Cluster memory leaks
  • Loading branch information
JavierJF authored May 17, 2024
2 parents 3cdbeba + 3d185ec commit 50e9d9a
Show file tree
Hide file tree
Showing 16 changed files with 452 additions and 330 deletions.
7 changes: 6 additions & 1 deletion include/ProxySQL_Cluster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,11 @@ struct fetch_query {
std::string msgs[3];
};

struct cluster_creds_t {
string user;
string pass;
};

class ProxySQL_Cluster {
private:
SQLite3DB* mydb;
Expand Down Expand Up @@ -444,7 +449,7 @@ class ProxySQL_Cluster {

MySQL_Monitor::trigger_dns_cache_update();
}
void get_credentials(char**, char**);
cluster_creds_t get_credentials();
void set_username(char*);
void set_password(char*);
void set_admin_mysql_ifaces(char*);
Expand Down
18 changes: 6 additions & 12 deletions lib/GTID_Server_Data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,14 @@ void connect_cb(EV_P_ ev_io *w, int revents) {
}

struct ev_io * new_connector(char *address, uint16_t gtid_port, uint16_t mysql_port) {
//struct sockaddr_in a;
int s;

if ((s = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
perror("socket");
close(s);
return NULL;
}
/*
memset(&a, 0, sizeof(a));
a.sin_port = htons(gtid_port);
a.sin_family = AF_INET;
if (!inet_aton(address, (struct in_addr *) &a.sin_addr.s_addr)) {
perror("bad IP address format");
close(s);
return NULL;
}
*/

ioctl_FIONBIO(s,1);

struct addrinfo hints;
Expand All @@ -142,15 +132,19 @@ struct ev_io * new_connector(char *address, uint16_t gtid_port, uint16_t mysql_p

char str_port[NI_MAXSERV+1];
sprintf(str_port,"%d", gtid_port);

int gai_rc = getaddrinfo(address, str_port, &hints, &res);
if (gai_rc) {
freeaddrinfo(res);
//exit here
return NULL;
}

//int status = connect(s, (struct sockaddr *) &a, sizeof(a));
int status = connect(s, res->ai_addr, res->ai_addrlen);

// Free linked list
freeaddrinfo(res);

if ((status == 0) || ((status == -1) && (errno == EINPROGRESS))) {
struct ev_io *c = (struct ev_io *)malloc(sizeof(struct ev_io));
if (c) {
Expand Down
8 changes: 8 additions & 0 deletions lib/MySQL_Monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4091,6 +4091,14 @@ void* monitor_GR_thread_HG(void *arg) {
// 3. Delegate the async fetching + actions of 'MySQL_Monitor_State_Data' with conns on 'Monitor_Poll'.
///////////////////////////////////////////////////////////////////////////////////////

// NOTE: This is just a best effort to avoid invalid memory accesses during 'SHUTDOWN SLOW'. Since the
// previous section is 'time consuming', there are good changes that we can detect a shutdown before
// trying to perform the monitoring actions on the acquired 'mmsd'. This exact scenario and timing has
// been previously observed in the CI.
if (GloMyMon->shutdown) {
break;
}

// Handle 'mmsds' that failed to optain conns
for (const unique_ptr<MySQL_Monitor_State_Data>& mmsd : fail_mmsds) {
async_gr_mon_actions_handler(mmsd.get());
Expand Down
3 changes: 3 additions & 0 deletions lib/ProxySQL_Admin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6033,6 +6033,7 @@ ProxySQL_Admin::ProxySQL_Admin() :
variables.p_memory_metrics_interval = 61;
#ifdef DEBUG
variables.debug=GloVars.global.gdbg;
all_modules_started = false;
debug_output = 1;
proxysql_set_admin_debug_output(debug_output);
#endif /* DEBUG */
Expand Down Expand Up @@ -6388,6 +6389,8 @@ bool ProxySQL_Admin::init(const bootstrap_info_t& bootstrap_info) {

Admin_HTTP_Server = NULL;
AdminRestApiServer = NULL;
AdminHTTPServer = NULL;

/*
AdminRestApiServer = new ProxySQL_RESTAPI_Server();
AdminRestApiServer->print_version();
Expand Down
Loading

0 comments on commit 50e9d9a

Please sign in to comment.