aerospike / aerospike-client-c

Aerospike C Client
Other
98 stars 103 forks source link

Deadlock / lost wakeup bug in as_monitor.h #72

Closed mbotner closed 7 years ago

mbotner commented 7 years ago

FYI, there is a deadlock / lost wakeup bug in as_monitor.h in the as_monitor_wait() function. Specifically, the complete flag is tested before the mutex is locked. Here's the original & corrected version and a diff:

original version -------------------------------

static inline void as_monitor_wait(as_monitor* monitor) { while (! monitor->complete) { pthread_mutex_lock(&monitor->lock); pthread_cond_wait(&monitor->cond, &monitor->lock); pthread_mutex_unlock(&monitor->lock); } }

corrected version ---------------------------

static inline void as_monitor_wait(as_monitor* monitor) { pthread_mutex_lock(&monitor->lock);

    while (! monitor->complete) {
            pthread_cond_wait(&monitor->cond, &monitor->lock);
    }
    pthread_mutex_unlock(&monitor->lock);

}

diff of old vs. new -------------------------------------

ip-172-31-20-184:1183$ diff as_monitor.h.orig as_monitor.h 60a61,62

pthread_mutex_lock(&monitor->lock);

62d63 < pthread_mutex_lock(&monitor->lock); 64d64 < pthread_mutex_unlock(&monitor->lock); 65a66 pthread_mutex_unlock(&monitor->lock);

BrianNichols commented 7 years ago

You are right. We will fix in the next release.

BrianNichols commented 7 years ago

C client version 4.2.0 fixes the problem.

http://www.aerospike.com/download/client/c/4.2.0