From 2cc50ba8d4d825e87a6672ad18f6bc3459075833 Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Fri, 8 Jan 2021 17:17:50 -0600 Subject: [PATCH] upstream: move counters update inside protected section Signed-off-by: Eduardo Silva --- src/flb_upstream.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/flb_upstream.c b/src/flb_upstream.c index e92a2dcb71b..824ee86ade8 100644 --- a/src/flb_upstream.c +++ b/src/flb_upstream.c @@ -248,8 +248,6 @@ static int destroy_conn(struct flb_upstream_conn *u_conn) flb_socket_close(u_conn->fd); } - u->n_connections--; - if (u->thread_safe == FLB_TRUE) { pthread_mutex_lock(&u->mutex_lists); } @@ -260,6 +258,8 @@ static int destroy_conn(struct flb_upstream_conn *u_conn) /* Add node to destroy queue */ mk_list_add(&u_conn->_head, &u->destroy_queue); + u->n_connections--; + if (u->thread_safe == FLB_TRUE) { pthread_mutex_unlock(&u->mutex_lists); } @@ -327,13 +327,13 @@ static struct flb_upstream_conn *create_conn(struct flb_upstream *u) /* Link new connection to the busy queue */ mk_list_add(&conn->_head, &u->busy_queue); + /* Increase counter */ + u->n_connections++; + if (u->thread_safe == FLB_TRUE) { pthread_mutex_unlock(&u->mutex_lists); } - /* Increase counter */ - u->n_connections++; - /* Start connection */ ret = flb_io_net_connect(conn, coro); if (ret == -1) { @@ -508,7 +508,7 @@ int flb_upstream_conn_release(struct flb_upstream_conn *conn) } mk_list_del(&conn->_head); - mk_list_add(&conn->_head, &conn->u->av_queue); + mk_list_add(&conn->_head, &u->av_queue); if (u->thread_safe == FLB_TRUE) { pthread_mutex_unlock(&u->mutex_lists);