#49592 Issue 49572 - ns_job_wait race on condvar
Merged 2 years ago by spichugi. Opened 2 years ago by spichugi.
spichugi/389-ds-base ns_test_fix  into  master

@@ -313,6 +313,7 @@ 

      struct ns_job_t *job = NULL;

      struct timespec timeout = {2, 0};


+     pthread_mutex_lock(&cb_lock);


          ns_create_job(tp, NS_JOB_NONE | NS_JOB_PERSIST, ns_init_disarm_job_cb, &job),


@@ -320,7 +321,6 @@ 

      assert_int_equal(ns_job_rearm(job), NS_SUCCESS);


      /* In the callback it should disarm */

-     pthread_mutex_lock(&cb_lock);

      assert(cond_wait_rel(&cb_cond, &cb_lock, &timeout) == 0);


      /* Make sure it did */

Bug description: ns_job_persist_disarm_test were failing
because of a race condition.

Fix description: We need to lock the cb mutex before we arm
the job so the order of operations that happens there is
First we lock the mutex, then after the rearm it will
disarm it and will wait inside for the mutex unlock.
In a meanwhile, our testing thread will come to cond_wait
and it will unlock the mutex while waiting for the signal.
The mutex inside of callback will be acquired and cb_check will set to 1
and the signal will be sent. After that, cond_wait will be released and
the test will check for the right cb_check value.


Reviewed by: wibrown (Thanks!)

Pull-Request has been merged by spichugi

2 years ago