#49592 Issue 49572 - ns_job_wait race on condvar
Closed 3 years ago by spichugi. Opened 6 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);

      assert_int_equal(

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

          NS_SUCCESS);
@@ -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);

      pthread_mutex_unlock(&cb_lock);

      /* 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
determined.
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.

https://pagure.io/389-ds-base/issue/49572

Reviewed by: wibrown (Thanks!)

Pull-Request has been merged by spichugi

6 years ago

389-ds-base is moving from Pagure to Github. This means that new issues and pull requests
will be accepted only in 389-ds-base's github repository.

This pull request has been cloned to Github as issue and is available here:
- https://github.com/389ds/389-ds-base/issues/2651

If you want to continue to work on the PR, please navigate to the github issue,
download the patch from the attachments and file a new pull request.

Thank you for understanding. We apologize for all inconvenience.

Pull-Request has been closed by spichugi

3 years ago