Skip to content

Commit

Permalink
Prevent locking when sending TLS handshake
Browse files Browse the repository at this point in the history
This could cause a hang:
Worker #1 gets list lock,
-> Worker #1 coro #1 sends TLS handshake
-> Worker #1 coro #1 yields
-> Worker #1 coro #2 tries to acquire list lock
-> deadlock :(
  • Loading branch information
hsmatulisgoogle committed Dec 21, 2020
1 parent 7814bbd commit f8b9d23
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/flb_upstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,10 @@ static struct flb_upstream_conn *create_conn(struct flb_upstream *u)

MK_EVENT_ZERO(&conn->event);

LOCK_OR_RETURN(&u->connection_pool_mutex, NULL);
/* Link new connection to the busy queue */
mk_list_add(&conn->_head, &u->busy_queue);
UNLOCK_OR_RETURN(&u->connection_pool_mutex, NULL);

/* Increase counter */
u->n_connections++;
Expand Down Expand Up @@ -407,8 +409,8 @@ struct flb_upstream_conn *flb_upstream_conn_get(struct flb_upstream *u)
LOCK_OR_RETURN(&u->connection_pool_mutex, NULL);
/* On non Keepalive mode, always create a new TCP connection */
if (u->net.keepalive == FLB_FALSE) {
conn = create_conn(u);
UNLOCK_OR_RETURN(&u->connection_pool_mutex, NULL);
return create_conn(u);
}

/*
Expand Down Expand Up @@ -455,7 +457,8 @@ struct flb_upstream_conn *flb_upstream_conn_get(struct flb_upstream *u)

/* No keepalive connection available, create a new one */
if (!conn) {
conn = create_conn(u);
UNLOCK_OR_RETURN(&u->connection_pool_mutex, NULL);
return create_conn(u);
}

UNLOCK_OR_RETURN(&u->connection_pool_mutex, NULL);
Expand Down

0 comments on commit f8b9d23

Please sign in to comment.