Merge pull request #1236 in FS/freeswitch from ~DRAGOS_OANCEA_NX/freeswitch-dragos-nx:feature/FS-10172_mod_event_socket-err_log to master

* commit 'e02631c0a8e105d93aa7132a4d2d7c0055d26912':
  FS-10172: mod_event_socket: handle return codes from switch_queue_trypush() , more verbose logging when we cannot enqueue
This commit is contained in:
Mike Jerris 2017-04-28 19:16:06 +00:00
commit e105da0b09
1 changed files with 23 additions and 8 deletions

View 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);
}