From 686c1c6c1f06ad155146b69f77b2a867332754d9 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 5 Feb 2009 17:14:12 +0000 Subject: [PATCH] tweak sofia profile shutdown git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@11656 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/mod/endpoints/mod_sofia/sofia.c | 18 ++++++++++++++---- src/switch_core_session.c | 4 ++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 9dc3b2210a..4759d377fb 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -692,7 +692,7 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void int use_100rel = !sofia_test_pflag(profile, PFLAG_DISABLE_100REL); int use_timer = !sofia_test_pflag(profile, PFLAG_DISABLE_TIMER); const char *supported = NULL; - int sanity = 4; + int sanity; switch_mutex_lock(mod_sofia_globals.mutex); mod_sofia_globals.threads++; @@ -831,9 +831,15 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void sofia_clear_pflag_locked(profile, PFLAG_RUNNING); switch_core_session_hupall_matching_var("sofia_profile_name", profile->name, SWITCH_CAUSE_MANAGER_REQUEST); + sanity = 10; while (profile->inuse) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Waiting for %d session(s)\n", profile->inuse); su_root_step(profile->s_root, 1000); + if (!--sanity) { + break; + } else if (sanity == 5) { + switch_core_session_hupall_matching_var("sofia_profile_name", profile->name, SWITCH_CAUSE_MANAGER_REQUEST); + } } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write lock %s\n", profile->name); @@ -841,6 +847,8 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void sofia_reg_unregister(profile); nua_shutdown(profile->nua); su_root_run(profile->s_root); + nua_shutdown(profile->nua); + su_root_run(profile->s_root); sofia_clear_pflag_locked(profile, PFLAG_RUNNING); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Waiting for worker thread\n"); @@ -848,16 +856,18 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void while (sofia_test_pflag(profile, PFLAG_WORKER_RUNNING)) { switch_yield(100000); } - + + sanity = 4; while (profile->inuse) { + switch_core_session_hupall_matching_var("sofia_profile_name", profile->name, SWITCH_CAUSE_MANAGER_REQUEST); switch_yield(5000000); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Waiting for %d session(s)\n", profile->inuse); - if (!sanity--) { + if (!--sanity) { break; } } nua_destroy(profile->nua); - + switch_mutex_lock(profile->ireg_mutex); switch_mutex_unlock(profile->ireg_mutex); diff --git a/src/switch_core_session.c b/src/switch_core_session.c index 2c67fc8468..6ee0a5afb8 100644 --- a/src/switch_core_session.c +++ b/src/switch_core_session.c @@ -142,8 +142,8 @@ SWITCH_DECLARE(void) switch_core_session_hupall(switch_call_cause_t cause) switch_mutex_unlock(runtime.throttle_mutex); while (session_manager.session_count > 0) { - switch_yield(100000); - if (++loops == 100) { + switch_yield(1000000); + if (++loops == 30) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Giving up with %d session%s remaining\n", session_manager.session_count, session_manager.session_count == 1 ? "" : "s"); break;