From 369206cf4f39e160a8cc9479a399a92cf22c3e44 Mon Sep 17 00:00:00 2001
From: Tamas Cseke <tamas.cseke@virtual-call-center.eu>
Date: Thu, 27 Feb 2014 08:13:57 +0100
Subject: [PATCH] FS-5991 --resolve

---
 .../event_handlers/mod_erlang_event/mod_erlang_event.c    | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c b/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c
index f7c943c396..5d85254735 100644
--- a/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c
+++ b/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c
@@ -397,6 +397,8 @@ static fetch_reply_t *new_fetch_reply(const char *uuid_str)
 	switch_mutex_init(&reply->mutex, SWITCH_MUTEX_UNNESTED, pool);
 	reply->state = reply_not_ready;
 	reply->reply = NULL;
+
+	switch_mutex_lock(reply->mutex);
 	switch_core_hash_insert_locked(globals.fetch_reply_hash, uuid_str, reply, globals.fetch_reply_mutex);
 	reply->state = reply_waiting;
 
@@ -422,7 +424,7 @@ fetch_reply_t *find_fetch_reply(const char *uuid)
 
 	switch_mutex_lock(globals.fetch_reply_mutex);
 	if ((reply = switch_core_hash_find(globals.fetch_reply_hash, uuid))) {
-		if (switch_mutex_trylock(reply->mutex) != SWITCH_STATUS_SUCCESS) {
+		if (switch_mutex_lock(reply->mutex) != SWITCH_STATUS_SUCCESS) {
 			reply = NULL;
 		}
 	}
@@ -512,9 +514,7 @@ static switch_xml_t erlang_fetch(const char *sectionstr, const char *tag_name, c
 		goto cleanup;
 	}
 
-	/* Tell the threads to be ready, and wait five seconds for a reply. */
-	switch_mutex_lock(p->mutex);
-	//p->state = reply_waiting;
+	/* Wait five seconds for a reply. */
 	switch_thread_cond_timedwait(p->ready_or_found, p->mutex, 5000000);
 	if (!p->reply) {
 		p->state = reply_timeout;