LDAP timeouts during failure conditions

Phil Mayers p.mayers at imperial.ac.uk
Tue Jun 28 18:17:25 CEST 2011


On 23/06/11 17:28, Alan DeKok wrote:

>    I'd really like 3.0 to have generic connection pools.  That would
> solve this problem by having common code, instead of stuff in rlm_sql,
> rlm_ldap, etc.

Do you have any pointers how to get started on this? Off the top of my 
head it seems we'd need something like the code below; a struct to hold 
module-supplied connection create/keepalive/delete functions, some code 
in the server core to set and re-set "last used" times and call a 
keepalive function, and delete


typedef struct {
   int alive;
   void *conn;
   /* mutex stuff */
} fr_pool_conn;

typedef struct {
   int pool_min;
   int pool_max;
   int pool_idle;
   fr_pool_conn *conns;

   void* (*conn_create)(void *arg);
   int (*conn_keepalive)(void *conn, void *arg);
   int (*conn_delete)(void *conn, void *arg);

   void *arg;

} fr_conn_pool;

...and then something like:

void* ldap_conn_create(void *arg) {

   ldap_instance *instance = arg;

   LDAP *blah = ldap_init(...)
   ldap_bind();
   if (fail)
     return NULL;
   return blah;
}

int ldap_conn_keepalive(void *conn, void *arg) {
   LDAP *blah = conn;
   ldap_instance *inst = arg;

   /* send some noop search
    * or e.g. "select 1" in rlm_sql
    */

   return 0
}

int ldap_conn_delete(void *conn, void *arg) {
   /* connection unused, close it
    */
}

int ldap_init(...) {

  inst->ldap_pool = fr_pool_create(
     5, /* min connection */,
     15, /* max connection */,
     60, /* idle time - if num > min, reap connections */,
     ldap_conn_create,
     ldap_conn_keepalive,
     ldap_conn_delete,
     inst /* argument to conn_{create,keepalive,delete}
  )

}

int perform_search() {

   ldap_instance *inst = ...;
   /* timeout argument - 0 == pool - seconds or microseconds? */
   LDAP *conn = fr_pool_get(&inst->ldap_pool, 0);
   /* stuff
   fr_pool_release(&inst->ldap_pool, conn);
}



More information about the Freeradius-Devel mailing list