Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a race condition in mk_list_add/del when connections are created/deleted #8013

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/monkey/mk_server/mk_scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ extern struct mk_sched_handler mk_http2_handler;

pthread_mutex_t mutex_worker_init = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t mutex_worker_exit = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t mutex_conn_timeout = PTHREAD_MUTEX_INITIALIZER;

/*
* Returns the worker id which should take a new incomming connection,
Expand Down Expand Up @@ -238,7 +239,9 @@ struct mk_sched_conn *mk_sched_add_connection(int remote_fd,
* The protocol handler is in charge to remove the session from the
* timeout_queue.
*/
pthread_mutex_lock(&mutex_conn_timeout);
mk_sched_conn_timeout_add(conn, sched);
pthread_mutex_unlock(&mutex_conn_timeout);

/* Linux trace message */
MK_LT_SCHED(remote_fd, "REGISTERED");
Expand Down Expand Up @@ -540,7 +543,9 @@ int mk_sched_remove_client(struct mk_sched_conn *conn,

/* Unlink from the red-black tree */
//rb_erase(&conn->_rb_head, &sched->rb_queue);
pthread_mutex_lock(&mutex_conn_timeout);
mk_sched_conn_timeout_del(conn);
pthread_mutex_unlock(&mutex_conn_timeout);

/* Close at network layer level */
conn->net->close(conn->net->plugin, event->fd);
Expand Down
Loading