ITS#9197 back-ldap: added task that prunes expired connections

parent dfe1f649
Pipeline #1340 passed with stage
in 28 minutes and 38 seconds
......@@ -417,6 +417,7 @@ typedef struct ldapinfo_t {
ldap_pvt_thread_mutex_t li_counter_mutex;
ldap_pvt_mp_t li_ops_completed[SLAP_OP_LAST];
struct re_s* li_conn_expire_task;
} ldapinfo_t;
#define LDAP_ERR_OK(err) ((err) == LDAP_SUCCESS || (err) == LDAP_COMPARE_FALSE || (err) == LDAP_COMPARE_TRUE)
......
......@@ -31,6 +31,7 @@
#include "slap.h"
#include "config.h"
#include "back-ldap.h"
#include "ldap_rq.h"
static const ldap_extra_t ldap_extra = {
ldap_back_proxy_authz_ctrl,
......@@ -44,6 +45,8 @@ static const ldap_extra_t ldap_extra = {
ldap_back_connid2str
};
static void *ldap_back_conn_expire_fn(void *ctx, void *arg);
int
ldap_back_open( BackendInfo *bi )
{
......@@ -185,6 +188,13 @@ ldap_back_db_init( Backend *be, ConfigReply *cr )
ldap_pvt_mp_init( li->li_ops_completed[ i ] );
}
/* start task that prunes expired connections */
ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
li->li_conn_expire_task = ldap_pvt_runqueue_insert( &slapd_rq, 1,
ldap_back_conn_expire_fn, li, "ldap_back_conn_expire_fn",
"ldab_back_conn_expire_timer" );
ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
be->be_private = li;
SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_NOLASTMOD;
......@@ -303,6 +313,14 @@ ldap_back_db_destroy( Backend *be, ConfigReply *cr )
(void)ldap_back_monitor_db_destroy( be );
/* stop and remove the task that prunes expired connections */
ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
if ( ldap_pvt_runqueue_isrunning( &slapd_rq, li->li_conn_expire_task ) ) {
ldap_pvt_runqueue_stoptask( &slapd_rq, li->li_conn_expire_task );
}
ldap_pvt_runqueue_remove( &slapd_rq, li->li_conn_expire_task );
ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
ldap_pvt_thread_mutex_lock( &li->li_conninfo.lai_mutex );
if ( li->li_uri != NULL ) {
......@@ -353,10 +371,49 @@ ldap_back_db_destroy( Backend *be, ConfigReply *cr )
return 0;
}
static void *
ldap_back_conn_expire_fn( void *ctx, void *arg )
{
struct re_s *rtask = arg;
ldapinfo_t *li = (ldapinfo_t *)rtask->arg;
ldap_pvt_thread_mutex_lock( &li->li_conninfo.lai_mutex );
int c;
for ( c = LDAP_BACK_PCONN_FIRST; c < LDAP_BACK_PCONN_LAST; c++ ) {
time_t now = slap_get_time();
ldapconn_t *lc = LDAP_TAILQ_FIRST( &li->li_conn_priv[ c ].lic_priv );
while ( lc ) {
ldapconn_t *next = LDAP_TAILQ_NEXT( lc, lc_q );
if ( li->li_conn_ttl != 0 && lc->lc_refcnt == 0 && now > lc->lc_create_time + li->li_conn_ttl ) {
Debug( LDAP_DEBUG_TRACE, "closing connection after %ld seconds TTL lc=%p\n", li->li_conn_ttl, lc );
LDAP_TAILQ_REMOVE( &li->li_conn_priv[ c ].lic_priv, lc, lc_q );
ldap_back_conn_free( lc );
} else if ( li->li_idle_timeout != 0 && lc->lc_refcnt == 0 && now > lc->lc_time + li->li_idle_timeout ) {
Debug( LDAP_DEBUG_TRACE, "closing connection after %ld seconds of inactivity lc=%p\n", li->li_idle_timeout, lc );
LDAP_TAILQ_REMOVE( &li->li_conn_priv[ c ].lic_priv, lc, lc_q );
ldap_back_conn_free( lc );
}
lc = next;
}
}
ldap_pvt_thread_mutex_unlock( &li->li_conninfo.lai_mutex );
/* reschedule */
ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
ldap_pvt_runqueue_stoptask( &slapd_rq, rtask );
ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
return NULL;
}
#if SLAPD_LDAP == SLAPD_MOD_DYNAMIC
/* conditionally define the init_module() function */
SLAP_BACKEND_INIT_MODULE( ldap )
#endif /* SLAPD_LDAP == SLAPD_MOD_DYNAMIC */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment