[syslog-ng] [PATCH] afmongodb: Fix a deadlock at deinit time.

Gergely Nagy algernon at balabit.hu
Fri Feb 3 10:52:57 CET 2012


There is a race condition between the writer thread and stop_threads
(via deinit): if deinit sends the signal just at the wrong time, then
the worker thread willl never wake up, as the main thread is already
waiting for a join to finish.

The fix is to lock the queue_mutex before signalling, that eliminates
the race. This patch does just that.

Signed-off-by: Gergely Nagy <algernon at balabit.hu>
---
 modules/afmongodb/afmongodb.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/modules/afmongodb/afmongodb.c b/modules/afmongodb/afmongodb.c
index 42c140e..dade669 100644
--- a/modules/afmongodb/afmongodb.c
+++ b/modules/afmongodb/afmongodb.c
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2002-2011 BalaBit IT Ltd, Budapest, Hungary
- * Copyright (c) 2010-2011 Gergely Nagy <algernon at balabit.hu>
+ * Copyright (c) 2010-2012 BalaBit IT Ltd, Budapest, Hungary
+ * Copyright (c) 2010-2012 Gergely Nagy <algernon at balabit.hu>
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 as published
@@ -403,7 +403,9 @@ static void
 afmongodb_dd_stop_thread (MongoDBDestDriver *self)
 {
   self->writer_thread_terminate = TRUE;
+  g_mutex_lock(self->queue_mutex);
   g_cond_signal(self->writer_thread_wakeup_cond);
+  g_mutex_unlock(self->queue_mutex);
   g_thread_join(self->writer_thread);
 }
 
-- 
1.7.8.3




More information about the syslog-ng mailing list