diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 1e9855edb8..6b9dd742b5 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -309,8 +309,6 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session) switch_event_header_t *hi; char *bye_headers = NULL; - sofia_set_flag_locked(tech_pvt, TFLAG_BYE); - SWITCH_STANDARD_STREAM(stream); if ((hi = switch_channel_variable_first(channel))) { for (; hi; hi = hi->next) { @@ -342,22 +340,25 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session) switch_channel_set_variable(channel, "sip_hangup_disposition", "send_bye"); } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Sending BYE to %s\n", switch_channel_get_name(channel)); - nua_bye(tech_pvt->nh, - SIPTAG_REASON_STR(reason), - TAG_IF(!switch_strlen_zero(bye_headers), SIPTAG_HEADER_STR(bye_headers)), - TAG_END()); + if (!sofia_test_flag(tech_pvt, TFLAG_BYE)) { + nua_bye(tech_pvt->nh, + SIPTAG_REASON_STR(reason), + TAG_IF(!switch_strlen_zero(bye_headers), SIPTAG_HEADER_STR(bye_headers)), + TAG_END()); + } } else { if (switch_channel_test_flag(channel, CF_OUTBOUND)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Sending CANCEL to %s\n", switch_channel_get_name(channel)); if (!tech_pvt->got_bye) { switch_channel_set_variable(channel, "sip_hangup_disposition", "send_cancel"); } - - nua_cancel(tech_pvt->nh, - SIPTAG_REASON_STR(reason), - TAG_IF(!switch_strlen_zero(bye_headers), SIPTAG_HEADER_STR(bye_headers)), - TAG_IF(!switch_strlen_zero(bye_headers), SIPTAG_HEADER_STR(bye_headers)), - TAG_END()); + if (!sofia_test_flag(tech_pvt, TFLAG_BYE)) { + nua_cancel(tech_pvt->nh, + SIPTAG_REASON_STR(reason), + TAG_IF(!switch_strlen_zero(bye_headers), SIPTAG_HEADER_STR(bye_headers)), + TAG_IF(!switch_strlen_zero(bye_headers), SIPTAG_HEADER_STR(bye_headers)), + TAG_END()); + } } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Responding to INVITE with: %d\n", sip_cause); if (!tech_pvt->got_bye) { @@ -372,7 +373,7 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session) } } - + sofia_set_flag_locked(tech_pvt, TFLAG_BYE); switch_safe_free(stream.data); }