From 9b9f8477f8c751e366a526e2177a8aab34c80f6d Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 26 Mar 2021 20:52:10 +0100 Subject: [PATCH] MEDIUM: backend: use a trylock to grab a connection on high FD counts as well Commit b1adf03df ("MEDIUM: backend: use a trylock when trying to grab an idle connection") solved a contention issue on the backend under normal condition, but there is another one further, which only happens when the number of FDs in use is considered too high, and which obviously causes random crashes with just 16 threads once the number of FDs is about to be exhausted. Like the aforementioned patch, this one should be backported to 2.3. --- src/backend.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/backend.c b/src/backend.c index 3cc7adc37..96ff6569b 100644 --- a/src/backend.c +++ b/src/backend.c @@ -1449,7 +1449,9 @@ int connect_server(struct stream *s) // see it possibly larger. ALREADY_CHECKED(i); - HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[i].idle_conns_lock); + if (HA_SPIN_TRYLOCK(IDLE_CONNS_LOCK, &idle_conns[i].idle_conns_lock) != 0) + continue; + node = ebmb_first(&srv->per_thr[i].idle_conns); if (node) { conn_node = ebmb_entry(node, struct conn_hash_node, node);