diff --git a/src/mod/event_handlers/mod_erlang_event/handle_msg.c b/src/mod/event_handlers/mod_erlang_event/handle_msg.c index 77088487aa..e6d0d7a5f9 100644 --- a/src/mod/event_handlers/mod_erlang_event/handle_msg.c +++ b/src/mod/event_handlers/mod_erlang_event/handle_msg.c @@ -1115,6 +1115,7 @@ static switch_status_t handle_ref_tuple(listener_t *listener, erlang_msg * msg, void *val; session_elem_t *se; switch_hash_index_t *iter; + int found = 0; ei_decode_tuple_header(buf->buff, &buf->index, &arity); @@ -1137,29 +1138,32 @@ static switch_status_t handle_ref_tuple(listener_t *listener, erlang_msg * msg, switch_hash_this(iter, &key, NULL, &val); se = (session_elem_t*)val; if (se->spawn_reply && !strncmp(se->spawn_reply->hash, hash, 100)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "found matching session for %s : %s\n", hash, se->uuid_str); + switch_mutex_lock(se->spawn_reply->mutex); - if (se->spawn_reply->state == reply_waiting) { - se->spawn_reply->pid = switch_core_alloc(se->pool, sizeof(erlang_pid)); - switch_assert(se->spawn_reply->pid != NULL); - memcpy(se->spawn_reply->pid, &pid, sizeof(erlang_pid)); - switch_thread_cond_signal(se->spawn_reply->ready_or_found); - ei_x_encode_atom(rbuf, "ok"); - switch_mutex_unlock(se->spawn_reply->mutex); - switch_thread_rwlock_unlock(listener->session_rwlock); - return SWITCH_STATUS_SUCCESS; - } + se->spawn_reply->pid = switch_core_alloc(se->pool, sizeof(erlang_pid)); + switch_assert(se->spawn_reply->pid != NULL); + memcpy(se->spawn_reply->pid, &pid, sizeof(erlang_pid)); + switch_thread_cond_signal(se->spawn_reply->ready_or_found); + switch_mutex_unlock(se->spawn_reply->mutex); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "get_pid came in too late for %s; %s\n", hash, se->uuid_str); + + found++; + break; } } switch_thread_rwlock_unlock(listener->session_rwlock); - ei_x_encode_tuple_header(rbuf, 2); - ei_x_encode_atom(rbuf, "error"); - ei_x_encode_atom(rbuf, "notfound"); + if (found) { + ei_x_encode_atom(rbuf, "ok"); + } else { + ei_x_encode_tuple_header(rbuf, 2); + ei_x_encode_atom(rbuf, "error"); + ei_x_encode_atom(rbuf, "notfound"); + } return SWITCH_STATUS_SUCCESS; } 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 4b3eaa7ecd..b8e13b2a5c 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 @@ -1376,7 +1376,6 @@ session_elem_t *attach_call_to_spawned_process(listener_t *listener, char *modul p = switch_core_alloc(session_element->pool, sizeof(*p)); switch_thread_cond_create(&p->ready_or_found, session_element->pool); switch_mutex_init(&p->mutex, SWITCH_MUTEX_UNNESTED, session_element->pool); - p->state = reply_waiting; p->hash = switch_core_strdup(session_element->pool, hash); p->pid = NULL; @@ -1421,7 +1420,6 @@ session_elem_t *attach_call_to_spawned_process(listener_t *listener, char *modul if (!p->pid) { switch_channel_t *channel = switch_core_session_get_channel(session); - p->state = reply_timeout; switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Timed out when waiting for outbound pid %s %s\n", hash, session_element->uuid_str); switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); return NULL; diff --git a/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.h b/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.h index d5f890d0a1..c1730b5dba 100644 --- a/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.h +++ b/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.h @@ -71,7 +71,6 @@ struct spawn_reply_struct { switch_thread_cond_t *ready_or_found; switch_mutex_t *mutex; - enum reply_state state; erlang_pid *pid; char *hash; };