Skip to content

Commit 6dee77f

Browse files
author
Qihoo360
committed
fix crash when two clients send queries to admin port simultaneously: only main-thread handles the admin queries
1 parent 837b281 commit 6dee77f

4 files changed

Lines changed: 33 additions & 9 deletions

File tree

plugins/admin/admin-plugin.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ static int network_mysqld_admin_plugin_apply_config(chassis *chas, chassis_plugi
608608
/**
609609
* call network_mysqld_con_accept() with this connection when we are done
610610
*/
611-
event_set(&(listen_sock->event), listen_sock->fd, EV_READ|EV_PERSIST, network_mysqld_con_accept, con);
611+
event_set(&(listen_sock->event), listen_sock->fd, EV_READ|EV_PERSIST, network_mysqld_admin_con_accept, con);
612612
event_base_set(chas->event_base, &(listen_sock->event));
613613
event_add(&(listen_sock->event), NULL);
614614

plugins/proxy/proxy-plugin.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,7 @@ int idle_rw(network_mysqld_con* con) {
510510
network_backend_t* backend = network_backends_get(backends, i);
511511
if (backend == NULL) continue;
512512

513-
network_connection_pool* pool = chassis_event_thread_pool(backend);
514-
if (pool == NULL) continue;
513+
if (chassis_event_thread_pool(backend) == NULL) continue;
515514

516515
if (backend->type == BACKEND_TYPE_RW && backend->state == BACKEND_STATE_UP) {
517516
ret = i;
@@ -533,8 +532,7 @@ int idle_ro(network_mysqld_con* con) {
533532
network_backend_t* backend = network_backends_get(backends, i);
534533
if (backend == NULL) continue;
535534

536-
network_connection_pool* pool = chassis_event_thread_pool(backend);
537-
if (pool == NULL) continue;
535+
if (chassis_event_thread_pool(backend) == NULL) continue;
538536

539537
if (backend->type == BACKEND_TYPE_RO && backend->state == BACKEND_STATE_UP) {
540538
if (max_conns == -1 || backend->connected_clients < max_conns) {
@@ -575,8 +573,7 @@ int wrr_ro(network_mysqld_con *con) {
575573
network_backend_t* backend = network_backends_get(backends, next_ndx);
576574
if (backend == NULL) goto next;
577575

578-
network_connection_pool* pool = chassis_event_thread_pool(backend);
579-
if (pool == NULL) goto next;
576+
if (chassis_event_thread_pool(backend) == NULL) goto next;
580577

581578
if (backend->type == BACKEND_TYPE_RO && backend->weight >= cur_weight && backend->state == BACKEND_STATE_UP) ndx = next_ndx;
582579

src/network-mysqld.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,7 +1823,6 @@ void network_mysqld_con_accept(int G_GNUC_UNUSED event_fd, short events, void *u
18231823

18241824
network_mysqld_add_connection(listen_con->srv, client_con);
18251825

1826-
18271826
/**
18281827
* inherit the config to the new connection
18291828
*/
@@ -1834,8 +1833,35 @@ void network_mysqld_con_accept(int G_GNUC_UNUSED event_fd, short events, void *u
18341833
//network_mysqld_con_handle(-1, 0, client_con);
18351834
//此处将client_con放入异步队列,然后ping工作线程,由工作线程去执行network_mysqld_con_handle,不再由主线程直接执行network_mysqld_con_handle
18361835
chassis_event_add(client_con);
1836+
}
18371837

1838-
return;
1838+
void network_mysqld_admin_con_accept(int G_GNUC_UNUSED event_fd, short events, void *user_data) {
1839+
network_mysqld_con *listen_con = user_data;
1840+
network_mysqld_con *client_con;
1841+
network_socket *client;
1842+
1843+
g_assert(events == EV_READ);
1844+
g_assert(listen_con->server);
1845+
1846+
client = network_socket_accept(listen_con->server);
1847+
if (!client) return;
1848+
1849+
/* looks like we open a client connection */
1850+
client_con = network_mysqld_con_new();
1851+
client_con->client = client;
1852+
1853+
NETWORK_MYSQLD_CON_TRACK_TIME(client_con, "accept");
1854+
1855+
network_mysqld_add_connection(listen_con->srv, client_con);
1856+
1857+
/**
1858+
* inherit the config to the new connection
1859+
*/
1860+
1861+
client_con->plugins = listen_con->plugins;
1862+
client_con->config = listen_con->config;
1863+
1864+
network_mysqld_con_handle(-1, 0, client_con);
18391865
}
18401866

18411867
/**

src/network-mysqld.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ NETWORK_API void network_mysqld_con_free(network_mysqld_con *con);
380380
* should be socket
381381
*/
382382
NETWORK_API void network_mysqld_con_accept(int event_fd, short events, void *user_data); /** event handler for accept() */
383+
NETWORK_API void network_mysqld_admin_con_accept(int event_fd, short events, void *user_data); /** event handler for accept() */
383384

384385
NETWORK_API int network_mysqld_con_send_ok(network_socket *con);
385386
NETWORK_API int network_mysqld_con_send_ok_full(network_socket *con, guint64 affected_rows, guint64 insert_id, guint16 server_status, guint16 warnings);

0 commit comments

Comments
 (0)