diff --git a/src/mod/applications/mod_callcenter/mod_callcenter.c b/src/mod/applications/mod_callcenter/mod_callcenter.c index b035b6d7f93..cc5875e3035 100644 --- a/src/mod/applications/mod_callcenter/mod_callcenter.c +++ b/src/mod/applications/mod_callcenter/mod_callcenter.c @@ -1771,7 +1771,7 @@ static void *SWITCH_THREAD_FUNC outbound_agent_thread_run(switch_thread_t *threa dialstr = switch_channel_expand_variables(member_channel, h->originate_string); switch_channel_set_app_flag_key(CC_APP_KEY, member_channel, CC_APP_AGENT_CONNECTING); - status = switch_ivr_originate(NULL, &agent_session, &cause, dialstr, globals.agent_originate_timeout, NULL, cid_name ? cid_name : h->member_cid_name, cid_number ? cid_number : h->member_cid_number, NULL, ovars, SOF_NONE, NULL, NULL); + status = switch_ivr_originate(member_session, &agent_session, &cause, dialstr, globals.agent_originate_timeout, NULL, cid_name ? cid_name : h->member_cid_name, cid_number ? cid_number : h->member_cid_number, NULL, ovars, SOF_NONE, NULL, NULL); /* Search for loopback agent */ if (status == SWITCH_STATUS_SUCCESS) { @@ -1922,6 +1922,8 @@ static void *SWITCH_THREAD_FUNC outbound_agent_thread_run(switch_thread_t *threa switch_safe_free(sql); if (atoi(res) == 0) { + /* Unexpected, it's possible the agent channel wasn't created when the agent that won the race was connected, so hangup the channel */ + switch_channel_hangup(switch_core_session_get_channel(agent_session), SWITCH_CAUSE_LOSE_RACE); goto done; } switch_core_session_hupall_matching_var("cc_member_pre_answer_uuid", h->member_uuid, SWITCH_CAUSE_LOSE_RACE); diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c index 23fd2125ef7..66f1f2913c4 100644 --- a/src/mod/applications/mod_dptools/mod_dptools.c +++ b/src/mod/applications/mod_dptools/mod_dptools.c @@ -4316,6 +4316,32 @@ static switch_call_cause_t group_outgoing_channel(switch_core_session_t *session } +typedef struct { + switch_mutex_t *outgoing_mutex; +} mod_dptools_session_t; + + +static mod_dptools_session_t *user_outgoing_get_session_data(switch_core_session_t *session) +{ + switch_channel_t *channel = switch_core_session_get_channel(session); + mod_dptools_session_t *sdata = NULL; + + if (!channel) { + return NULL; + } + + sdata = (mod_dptools_session_t *) switch_channel_get_private(channel, "mod_dptools.session"); + + if (!sdata) { + /* allocate in session pool so it's auto-freed */ + sdata = (mod_dptools_session_t *) switch_core_session_alloc(session, sizeof(*sdata)); + sdata->outgoing_mutex = NULL; + switch_mutex_init(&sdata->outgoing_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); + switch_channel_set_private(channel, "mod_dptools.session", sdata); + } + + return sdata; +} /* fake chan_user */ switch_endpoint_interface_t *user_endpoint_interface; @@ -4425,6 +4451,7 @@ static switch_call_cause_t user_outgoing_channel(switch_core_session_t *session, switch_originate_flag_t myflags = SOF_NONE; char *cid_name_override = NULL; char *cid_num_override = NULL; + mod_dptools_session_t *sdata = NULL; if (var_event) { cid_name_override = switch_event_get_header(var_event, "origination_caller_id_name"); @@ -4433,6 +4460,13 @@ static switch_call_cause_t user_outgoing_channel(switch_core_session_t *session, if (session) { channel = switch_core_session_get_channel(session); + sdata = user_outgoing_get_session_data(session); + + if (sdata && sdata->outgoing_mutex) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "User/%s@%s locking outgoing mutex\n", dialed_user, domain); + switch_mutex_lock(sdata->outgoing_mutex); + } + if ((varval = switch_channel_get_variable(channel, SWITCH_CALL_TIMEOUT_VARIABLE)) || (var_event && (varval = switch_event_get_header(var_event, "leg_timeout")))) { timelimit = atoi(varval); @@ -4442,6 +4476,12 @@ static switch_call_cause_t user_outgoing_channel(switch_core_session_t *session, switch_channel_set_variable(channel, "dialed_domain", domain); d_dest = switch_channel_expand_variables(channel, dest); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "User/%s@%s d_dest: %s\n", dialed_user, domain, d_dest); + if (sdata && sdata->outgoing_mutex) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "User/%s@%s unlocking outgoing mutex\n", dialed_user, domain); + switch_mutex_unlock(sdata->outgoing_mutex); + } + } else { switch_event_t *event = NULL;