]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-10172: mod_event_socket: handle return codes from switch_queue_trypush() , more...
authorDragos Oancea <dragos.oancea@nexmo.com>
Thu, 23 Mar 2017 13:01:45 +0000 (13:01 +0000)
committerDragos Oancea <dragos.oancea@nexmo.com>
Mon, 27 Mar 2017 08:21:07 +0000 (09:21 +0100)
src/mod/event_handlers/mod_event_socket/mod_event_socket.c

index 415e30131a26efbb495f4b47bed6b45395766f6a..82bd7b9f79bf886413b822c84531fccb7fb1ffc2 100644 (file)
@@ -168,22 +168,29 @@ static void launch_listener_thread(listener_t *listener);
 static switch_status_t socket_logger(const switch_log_node_t *node, switch_log_level_t level)
 {
        listener_t *l;
-
+       switch_status_t qstatus;
        switch_mutex_lock(globals.listener_mutex);
        for (l = listen_list.listeners; l; l = l->next) {
                if (switch_test_flag(l, LFLAG_LOG) && l->level >= node->level) {
                        switch_log_node_t *dnode = switch_log_node_dup(node);
-
-                       if (switch_queue_trypush(l->log_queue, dnode) == SWITCH_STATUS_SUCCESS) {
+                       qstatus = switch_queue_trypush(l->log_queue, dnode); 
+                       if (qstatus == SWITCH_STATUS_SUCCESS) {
                                if (l->lost_logs) {
                                        int ll = l->lost_logs;
                                        l->lost_logs = 0;
-                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Lost %d log lines!\n", ll);
+                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Lost [%d] log lines! Log Queue size: [%u/%u]\n", ll, switch_queue_size(l->log_queue), MAX_QUEUE_LEN);
                                }
                        } else {
+                               char errbuf[512] = {0};
+                               unsigned int qsize = switch_queue_size(l->log_queue);
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, 
+                                               "Log enqueue ERROR [%d] | [%s] Queue size: [%u/%u] %s\n", 
+                                               (int)qstatus, switch_strerror(qstatus, errbuf, sizeof(errbuf)), qsize, MAX_QUEUE_LEN, (qsize == MAX_QUEUE_LEN)?"Max queue size reached":"");
                                switch_log_node_free(&dnode);
                                if (++l->lost_logs > MAX_MISSED) {
-                                       kill_listener(l, NULL);
+                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, 
+                                                       "Killing listener because of too many lost log lines. Lost [%d] Queue size [%u/%u]!\n", l->lost_logs, qsize, MAX_QUEUE_LEN);
+                                       kill_listener(l, "killed listener because of lost log lines\n");
                                }
                        }
                }
@@ -264,6 +271,7 @@ static void event_handler(switch_event_t *event)
        switch_event_t *clone = NULL;
        listener_t *l, *lp, *last = NULL;
        time_t now = switch_epoch_time_now(NULL);
+       switch_status_t qstatus;
 
        switch_assert(event != NULL);
 
@@ -371,15 +379,22 @@ static void event_handler(switch_event_t *event)
 
                if (send) {
                        if (switch_event_dup(&clone, event) == SWITCH_STATUS_SUCCESS) {
-                               if (switch_queue_trypush(l->event_queue, clone) == SWITCH_STATUS_SUCCESS) {
+                               qstatus = switch_queue_trypush(l->event_queue, clone); 
+                               if (qstatus == SWITCH_STATUS_SUCCESS) {
                                        if (l->lost_events) {
                                                int le = l->lost_events;
                                                l->lost_events = 0;
-                                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(l->session), SWITCH_LOG_CRIT, "Lost %d events!\n", le);
+                                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(l->session), SWITCH_LOG_CRIT, "Lost [%d] events! Event Queue size: [%u/%u]\n", le, switch_queue_size(l->event_queue), MAX_QUEUE_LEN);
                                        }
                                } else {
+                                       char errbuf[512] = {0};
+                                       unsigned int qsize = switch_queue_size(l->event_queue);
+                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, 
+                                                       "Event enqueue ERROR [%d] | [%s] | Queue size: [%u/%u] %s\n", 
+                                                       (int)qstatus, switch_strerror(qstatus, errbuf, sizeof(errbuf)), qsize, MAX_QUEUE_LEN, (qsize == MAX_QUEUE_LEN)?"Max queue size reached":"");
                                        if (++l->lost_events > MAX_MISSED) {
-                                               kill_listener(l, NULL);
+                                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Killing listener because of too many lost events. Lost [%d] Queue size[%u/%u]\n", l->lost_events, qsize, MAX_QUEUE_LEN);
+                                               kill_listener(l, "killed listener because of lost events\n");
                                        }
                                        switch_event_destroy(&clone);
                                }