Skip to content

Commit 3d25bff

Browse files
authored
Merge pull request #19 from freeswitch/fix_disconnect_hang
Fix ASR channel hang when MRCP server disconnects.
2 parents 4ea6938 + e48ee94 commit 3d25bff

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

mod_unimrcp.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2551,6 +2551,9 @@ static switch_status_t recog_channel_check_results(speech_channel_t *schannel)
25512551
if (!zstr(r->result)) {
25522552
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(schannel->session_uuid), SWITCH_LOG_DEBUG, "(%s) SUCCESS, have result\n", schannel->name);
25532553
status = SWITCH_STATUS_SUCCESS;
2554+
} else if (schannel->state == SPEECH_CHANNEL_CLOSED || schannel->state == SPEECH_CHANNEL_ERROR) {
2555+
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(schannel->session_uuid), SWITCH_LOG_WARNING, "Closing speech channel due to invalid state [%s]\n", speech_channel_state_to_string(schannel->state));
2556+
status = SWITCH_STATUS_FALSE;
25542557
}
25552558

25562559
switch_mutex_unlock(schannel->mutex);
@@ -3599,6 +3602,15 @@ static apt_bool_t recog_message_handler(const mrcp_app_message_t *app_message)
35993602
return mrcp_application_message_dispatch(&globals.recog.dispatcher, app_message);
36003603
}
36013604

3605+
static apt_bool_t recog_on_terminate_event(mrcp_application_t *application, mrcp_session_t *session, mrcp_channel_t *channel)
3606+
{
3607+
/* We may get this (terminate) event when the server disconnects. Terminating the session forces closing of
3608+
* the speech channel so we can stop recognition in recog_channel_check_results(). */
3609+
mrcp_application_session_terminate(session);
3610+
3611+
return TRUE;
3612+
}
3613+
36023614
/**
36033615
* Handle the MRCP responses/events
36043616
*/
@@ -3654,6 +3666,8 @@ static apt_bool_t recog_on_message_receive(mrcp_application_t *application, mrcp
36543666
} else {
36553667
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(schannel->session_uuid), SWITCH_LOG_DEBUG, "(%s) timers failed to start, status code = %d\n", schannel->name,
36563668
message->start_line.status_code);
3669+
/* Set ERROR state here to prevent call hang if server disconnects and can't respond to START-INPUT-TIMERS request. */
3670+
speech_channel_set_state(schannel, SPEECH_CHANNEL_ERROR);
36573671
}
36583672
}
36593673
} else if (message->start_line.method_id == RECOGNIZER_DEFINE_GRAMMAR) {
@@ -3807,6 +3821,7 @@ static switch_status_t recog_load(switch_loadable_module_interface_t *module_int
38073821
globals.recog.dispatcher.on_channel_add = speech_on_channel_add;
38083822
globals.recog.dispatcher.on_channel_remove = speech_on_channel_remove;
38093823
globals.recog.dispatcher.on_message_receive = recog_on_message_receive;
3824+
globals.recog.dispatcher.on_terminate_event = recog_on_terminate_event;
38103825
globals.recog.audio_stream_vtable.destroy = NULL;
38113826
globals.recog.audio_stream_vtable.open_rx = recog_stream_open;
38123827
globals.recog.audio_stream_vtable.close_rx = NULL;

0 commit comments

Comments
 (0)