]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
ITS#9878 Have refint use interval 0 to schedule its task
authorOndřej Kuzník <ondra@mistotebe.net>
Fri, 23 Sep 2022 11:55:38 +0000 (12:55 +0100)
committerQuanah Gibson-Mount <quanah@openldap.org>
Mon, 26 Sep 2022 17:34:21 +0000 (17:34 +0000)
Since the task is not rescheduled until a new operation comes in, close
a race where the reschedule chooses to stop it while the new item is
being added.

servers/slapd/overlays/refint.c

index dc7077d0de23cb9be4b73ad975169d7d25966914..a704e42373ca7876b812b66a05cd879820148875 100644 (file)
@@ -96,8 +96,6 @@ typedef struct refint_pre_s {
        int do_sub;
 } refint_pre;
 
-#define        RUNQ_INTERVAL   36000   /* a long time */
-
 static MatchingRule    *mr_dnSubtreeMatch;
 
 enum {
@@ -921,18 +919,18 @@ refint_qtask( void *ctx, void *arg )
                fptr = f_next;
        }
 
-       /* wait until we get explicitly scheduled again */
+       /* wait until there's more work to do */
+       ldap_pvt_thread_mutex_lock( &id->qmutex );
        ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
        ldap_pvt_runqueue_stoptask( &slapd_rq, id->qtask );
-       if ( pausing ) {
-               /* try to run again as soon as the pause is done */
-               id->qtask->interval.tv_sec = 0;
+       if ( pausing || id->qhead ) {
+               /* try to run again when possible */
                ldap_pvt_runqueue_resched( &slapd_rq, id->qtask, 0 );
-               id->qtask->interval.tv_sec = RUNQ_INTERVAL;
        } else {
-               ldap_pvt_runqueue_resched( &slapd_rq,id->qtask, 1 );
+               ldap_pvt_runqueue_resched( &slapd_rq, id->qtask, 1 );
        }
        ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
+       ldap_pvt_thread_mutex_unlock( &id->qmutex );
 
        return NULL;
 }
@@ -986,15 +984,12 @@ refint_response(
 
        ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
        if ( !id->qtask ) {
-               id->qtask = ldap_pvt_runqueue_insert( &slapd_rq, RUNQ_INTERVAL,
+               id->qtask = ldap_pvt_runqueue_insert( &slapd_rq, 0,
                        refint_qtask, id, "refint_qtask",
                        op->o_bd->be_suffix[0].bv_val );
        } else {
-               if ( !ldap_pvt_runqueue_isrunning( &slapd_rq, id->qtask ) &&
-                       !id->qtask->next_sched.tv_sec ) {
-                       id->qtask->interval.tv_sec = 0;
+               if ( !ldap_pvt_runqueue_isrunning( &slapd_rq, id->qtask ) ) {
                        ldap_pvt_runqueue_resched( &slapd_rq, id->qtask, 0 );
-                       id->qtask->interval.tv_sec = RUNQ_INTERVAL;
                }
        }
        ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );