From d3fbf2f61dc054c5b32b1b943ca91bd352bf6a1a Mon Sep 17 00:00:00 2001 From: lazio579 Date: Thu, 20 Dec 2018 11:47:07 +0800 Subject: [PATCH] Close server connections when adjusting attribute failed --- plugins/proxy/proxy-plugin.c | 6 ++++++ src/chassis-event.c | 4 ---- src/network-mysqld-packet.c | 2 ++ src/network-mysqld.c | 17 ++++++++++++++++- src/network-mysqld.h | 1 + 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/plugins/proxy/proxy-plugin.c b/plugins/proxy/proxy-plugin.c index 34ff312..5771b3f 100644 --- a/plugins/proxy/proxy-plugin.c +++ b/plugins/proxy/proxy-plugin.c @@ -275,6 +275,12 @@ proxy_c_read_query_result(network_mysqld_con *con) break; } + if (inj->id > INJ_ID_COM_STMT_PREPARE && inj->id < INJ_ID_RESET_CONNECTION) { + if (res->qstat.query_status == MYSQLD_PACKET_ERR) { + con->resp_err_met = 1; + } + } + if (is_continue) { if (res->qstat.query_status) { if (con->is_in_transaction) { diff --git a/src/chassis-event.c b/src/chassis-event.c index cd4e9c7..1ed88aa 100644 --- a/src/chassis-event.c +++ b/src/chassis-event.c @@ -111,7 +111,6 @@ chassis_event_loop(chassis_event_loop_t *loop, int *mutex) struct timeval timeout; int r; - g_debug("%s: enter event_base_loopexit", G_STRLOC); timeout.tv_sec = 0; timeout.tv_usec = 256000; @@ -121,9 +120,7 @@ chassis_event_loop(chassis_event_loop_t *loop, int *mutex) break; } - g_debug("%s: enter event_base_dispatch", G_STRLOC); r = event_base_dispatch(loop); - g_debug("%s: after event_base_dispatch:%d", G_STRLOC, r); if (r == -1) { g_debug("%s: after event_base_dispatch:%d, errno:%d, str:%s", @@ -138,7 +135,6 @@ chassis_event_loop(chassis_event_loop_t *loop, int *mutex) } } - g_debug("%s: leave chassis_event_loop", G_STRLOC); return NULL; } diff --git a/src/network-mysqld-packet.c b/src/network-mysqld-packet.c index 23f846b..cef2667 100644 --- a/src/network-mysqld-packet.c +++ b/src/network-mysqld-packet.c @@ -454,6 +454,7 @@ network_mysqld_proto_get_com_init_db(network_packet *packet, switch (status) { case MYSQLD_PACKET_ERR: is_finished = 1; + con->resp_err_met = 1; if (udata->db_name && udata->db_name->len) { g_message("%s: COM_INIT_DB failed, want db:%s, client default db still:%s", G_STRLOC, udata->db_name->str, con->client->default_db->str); @@ -487,6 +488,7 @@ network_mysqld_proto_get_com_init_db(network_packet *packet, break; default: g_critical("%s: COM_INIT_DB should be (ERR|OK), got %02x", G_STRLOC, status); + con->resp_err_met = 1; return -1; } diff --git a/src/network-mysqld.c b/src/network-mysqld.c index b775d3f..86da782 100644 --- a/src/network-mysqld.c +++ b/src/network-mysqld.c @@ -902,6 +902,8 @@ disp_err_packet(network_mysqld_con *con, network_packet *packet) packet->offset = NET_HEADER_SIZE; err_packet = network_mysqld_err_packet_new(); + con->resp_err_met = 1; + if (!network_mysqld_proto_get_err_packet(packet, err_packet)) { g_message("%s: dst:%s, sql:%s, errmsg:%s", G_STRLOC, con->server->dst->name->str, con->orig_sql->str, err_packet->errmsg->str); @@ -2724,6 +2726,8 @@ handle_send_query_to_servers(network_mysqld_con *con, network_mysqld_con_state_t { int disp_flag = 0; + con->resp_err_met = 0; + /* * send the query to the server * this state will loop until all the packets @@ -3273,7 +3277,18 @@ disp_attr(network_mysqld_con *con, int srv_down_count, int *disp_flag) *disp_flag = DISP_CONTINUE; return 0; - + } else if (con->resp_err_met) { + con->state = ST_SEND_QUERY_RESULT; + network_queue_clear(con->client->send_queue); + network_mysqld_con_send_error_full(con->client, C("adjust connection attribute failed"), ER_CETUS_UNKNOWN, "HY000"); + g_warning("%s: adjust connection attribute failed for con:%p, attr state:%d, src:%s", + G_STRLOC, con, con->attr_adj_state, con->client->src->name->str); + remove_mul_server_recv_packets(con); + network_queue_clear(con->client->recv_queue); + network_mysqld_queue_reset(con->client); + con->server_to_be_closed = 1; + *disp_flag = DISP_CONTINUE; + return 0; } else { if (build_attr_statements(con)) { g_debug("%s: continue here:%d", G_STRLOC, con->state); diff --git a/src/network-mysqld.h b/src/network-mysqld.h index a1d140e..34ed606 100644 --- a/src/network-mysqld.h +++ b/src/network-mysqld.h @@ -569,6 +569,7 @@ struct network_mysqld_con { unsigned int query_cache_judged:1; unsigned int is_client_compressed:1; unsigned int is_admin_client:1; + unsigned int resp_err_met:1; unsigned int direct_answer:1; unsigned int admin_read_merge:1; unsigned int ask_one_worker:1;