]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Prevent multiple CDR batches from conflicting when scheduling the CDR write
authorMatthew Jordan <mjordan@digium.com>
Sat, 3 Nov 2012 23:44:30 +0000 (23:44 +0000)
committerMatthew Jordan <mjordan@digium.com>
Sat, 3 Nov 2012 23:44:30 +0000 (23:44 +0000)
The Asterisk Test Suite caught an error condition where a scheduled CDR batch
write can be deleted twice if two channels attempt to post their CDRs at the
same time.  The batch CDR mutex is locked while the CDRs are appended to the
current batch list; however, it is unlocked prior to actually scheduling the
CDR write.  As such, two threads can attempt to remove the currently scheduled
batch write at the same time, resulting in an assertion error.

This patch extends the time that the mutex is locked to encompass actually
scheduling the write.  This prevents two threads from unscheduling the
currently scheduled write at the same time.

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@375727 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/cdr.c

index 58ba558d8e0fcf5f675862481d8f38636b4ac38a..2203a99c6b5ac2ec6494af8380e23586e64f4e5a 100644 (file)
@@ -1364,11 +1364,13 @@ void ast_cdr_detach(struct ast_cdr *cdr)
        newtail->cdr = cdr;
        batch->tail = newtail;
        curr = batch->size++;
-       ast_mutex_unlock(&cdr_batch_lock);
 
        /* if we have enough stuff to post, then do it */
-       if (curr >= (batchsize - 1))
+       if (curr >= (batchsize - 1)) {
                submit_unscheduled_batch();
+       }
+
+       ast_mutex_unlock(&cdr_batch_lock);
 }
 
 static void *do_cdr(void *data)