[syslog-ng] [PATCH 1/1] afmongodb: Fix a race condition in the queue & wakeup mechanism
Gergely Nagy
algernon at balabit.hu
Fri Mar 23 16:24:01 CET 2012
The problem was found and analysed by Whille, the patch is based on
his observations.
The patch corrects a situation where - due to a race condition - the
worker thread could end up in a permanent sleeping state.
Reported-by: whille <whille at 163.com>
Signed-off-by: Gergely Nagy <algernon at balabit.hu>
---
modules/afmongodb/afmongodb.c | 18 ++++++------------
1 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/modules/afmongodb/afmongodb.c b/modules/afmongodb/afmongodb.c
index 42c140e..47b6c9d 100644
--- a/modules/afmongodb/afmongodb.c
+++ b/modules/afmongodb/afmongodb.c
@@ -515,27 +515,21 @@ static void
afmongodb_dd_queue(LogPipe *s, LogMessage *msg, const LogPathOptions *path_options, gpointer user_data)
{
MongoDBDestDriver *self = (MongoDBDestDriver *)s;
- gboolean queue_was_empty;
LogPathOptions local_options;
if (!path_options->flow_control_requested)
path_options = log_msg_break_ack(msg, path_options, &local_options);
- g_mutex_lock(self->queue_mutex);
self->last_msg_stamp = cached_g_current_time_sec ();
- queue_was_empty = log_queue_get_length(self->queue) == 0;
- g_mutex_unlock(self->queue_mutex);
-
- log_queue_push_tail(self->queue, msg, path_options);
g_mutex_lock(self->suspend_mutex);
- if (queue_was_empty && !self->writer_thread_suspended)
- {
- g_mutex_lock(self->queue_mutex);
- log_queue_set_parallel_push(self->queue, 1, afmongodb_dd_queue_notify, self, NULL);
- g_mutex_unlock(self->queue_mutex);
- }
+ g_mutex_lock(self->queue_mutex);
+ if (!self->writer_thread_suspended)
+ log_queue_set_parallel_push(self->queue, 1, afmongodb_dd_queue_notify,
+ self, NULL);
+ g_mutex_unlock(self->queue_mutex);
g_mutex_unlock(self->suspend_mutex);
+ log_queue_push_tail(self->queue, msg, path_options);
}
/*
--
1.7.9
More information about the syslog-ng
mailing list