Author: anthm Date: Thu Feb 5 11:14:12 2009 New Revision: 11656 Log: tweak sofia profile shutdown Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c freeswitch/trunk/src/switch_core_session.c Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c ============================================================================== --- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c (original) +++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c Thu Feb 5 11:14:12 2009 @@ -692,7 +692,7 @@ 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 @@ 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 @@ 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 @@ 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); Modified: freeswitch/trunk/src/switch_core_session.c ============================================================================== --- freeswitch/trunk/src/switch_core_session.c (original) +++ freeswitch/trunk/src/switch_core_session.c Thu Feb 5 11:14:12 2009 @@ -142,8 +142,8 @@ 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;