From 0dd88a9e077cd7b8b3d3f317a1329438a4d35ed3 Mon Sep 17 00:00:00 2001 From: progier389 Date: Mon, 7 Aug 2023 10:18:19 +0200 Subject: [PATCH 10/11] Issue 5883 - Remove connection mutex contention risk on autobind (#5886) Problem: A contention on the connection c_mutex is blocking the listener thread when autobind is performed. Solution: Let the listener thread skip the connection if the mutex is held by another thread Reviewed by: @mreynolds389 , @droideck Thanks (cherry picked from commit 599db0a450357e804072ca03421c9f65351cdf1f) --- ldap/servers/slapd/daemon.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ldap/servers/slapd/daemon.c b/ldap/servers/slapd/daemon.c index e5b7d6e06..e44d0c9b5 100644 --- a/ldap/servers/slapd/daemon.c +++ b/ldap/servers/slapd/daemon.c @@ -1675,7 +1675,13 @@ handle_pr_read_ready(Connection_Table *ct, PRIntn num_poll __attribute__((unused continue; } - pthread_mutex_lock(&(c->c_mutex)); + /* Try to get connection mutex, if not available just skip the connection and + * process other connections events. May generates cpu load for listening thread + * if connection mutex is held for a long time + */ + if (pthread_mutex_trylock(&(c->c_mutex)) == EBUSY) { + continue; + } if (connection_is_active_nolock(c) && c->c_gettingber == 0) { PRInt16 out_flags; short readready; -- 2.41.0