]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Cleanup after outbound sessions that exit before the call hangs up
authorAndrew Thompson <andrew@hijacked.us>
Wed, 29 Jul 2009 23:13:02 +0000 (23:13 +0000)
committerAndrew Thompson <andrew@hijacked.us>
Wed, 29 Jul 2009 23:13:02 +0000 (23:13 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@14427 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c

index 24a00d0cefd14ad45fbfcef3f0afd00ccac9b3f5..389a2a22e2ba9ac4464fb825f69a75ec48909992 100644 (file)
@@ -679,8 +679,16 @@ static void handle_exit(listener_t *listener, erlang_pid *pid)
        remove_binding(NULL, pid); /* TODO - why don't we pass the listener as the first argument? */
        if ((s = find_session_elem_by_pid(listener, pid))) {
                if (s->channel_state < CS_HANGUP) {
+                       switch_core_session_t *session;
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Outbound session for %s exited unexpectedly!\n",
                                        s->uuid_str);
+                       
+                       if ((session = switch_core_session_locate(s->uuid_str))) {
+                               switch_channel_t *channel = switch_core_session_get_channel(session);
+                               switch_channel_set_private(channel, "_erlang_session_", NULL);
+                               switch_channel_set_private(channel, "_erlang_listener_", NULL);
+                               /* TODO can we clear out the state_change hook too? */
+                       }
                        /* TODO - if a spawned process that was handling an outbound call fails.. what do we do with the call? */
                }
                remove_session_elem_from_listener_locked(listener, s);
@@ -1064,7 +1072,8 @@ static switch_status_t state_handler(switch_core_session_t *session)
        session_elem_t *session_element = switch_channel_get_private(channel, "_erlang_session_");
        /*listener_t* listener = switch_channel_get_private(channel, "_erlang_listener_");*/
        
-       session_element->channel_state = state;
+       if (session_element)
+               session_element->channel_state = state;
 
        return SWITCH_STATUS_SUCCESS;
 }
@@ -1295,8 +1304,12 @@ SWITCH_STANDARD_APP(erlang_outbound_function)
 
                        /* keep app thread running for lifetime of session */
                        if (switch_channel_down(switch_core_session_get_channel(session))) {
-                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "outbound session all done\n");
-                               switch_clear_flag_locked(session_element, LFLAG_SESSION_ALIVE);
+                               if ((session_element = switch_channel_get_private(switch_core_session_get_channel(session), "_erlang_session_"))) {
+                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "outbound session all done\n");
+                                       switch_clear_flag_locked(session_element, LFLAG_SESSION_ALIVE);
+                               } else {
+                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "outbound session already done\n");
+                               }
                        }
                }
        }