FS-10172: mod_event_socket: handle return codes from switch_queue_trypush() , more verbose logging when we cannot enqueue
This commit is contained in:
parent
79c62475f0
commit
e02631c0a8
|
@ -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)
|
static switch_status_t socket_logger(const switch_log_node_t *node, switch_log_level_t level)
|
||||||
{
|
{
|
||||||
listener_t *l;
|
listener_t *l;
|
||||||
|
switch_status_t qstatus;
|
||||||
switch_mutex_lock(globals.listener_mutex);
|
switch_mutex_lock(globals.listener_mutex);
|
||||||
for (l = listen_list.listeners; l; l = l->next) {
|
for (l = listen_list.listeners; l; l = l->next) {
|
||||||
if (switch_test_flag(l, LFLAG_LOG) && l->level >= node->level) {
|
if (switch_test_flag(l, LFLAG_LOG) && l->level >= node->level) {
|
||||||
switch_log_node_t *dnode = switch_log_node_dup(node);
|
switch_log_node_t *dnode = switch_log_node_dup(node);
|
||||||
|
qstatus = switch_queue_trypush(l->log_queue, dnode);
|
||||||
if (switch_queue_trypush(l->log_queue, dnode) == SWITCH_STATUS_SUCCESS) {
|
if (qstatus == SWITCH_STATUS_SUCCESS) {
|
||||||
if (l->lost_logs) {
|
if (l->lost_logs) {
|
||||||
int ll = l->lost_logs;
|
int ll = l->lost_logs;
|
||||||
l->lost_logs = 0;
|
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 {
|
} 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);
|
switch_log_node_free(&dnode);
|
||||||
if (++l->lost_logs > MAX_MISSED) {
|
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;
|
switch_event_t *clone = NULL;
|
||||||
listener_t *l, *lp, *last = NULL;
|
listener_t *l, *lp, *last = NULL;
|
||||||
time_t now = switch_epoch_time_now(NULL);
|
time_t now = switch_epoch_time_now(NULL);
|
||||||
|
switch_status_t qstatus;
|
||||||
|
|
||||||
switch_assert(event != NULL);
|
switch_assert(event != NULL);
|
||||||
|
|
||||||
|
@ -371,15 +379,22 @@ static void event_handler(switch_event_t *event)
|
||||||
|
|
||||||
if (send) {
|
if (send) {
|
||||||
if (switch_event_dup(&clone, event) == SWITCH_STATUS_SUCCESS) {
|
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) {
|
if (l->lost_events) {
|
||||||
int le = l->lost_events;
|
int le = l->lost_events;
|
||||||
l->lost_events = 0;
|
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 {
|
} 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) {
|
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);
|
switch_event_destroy(&clone);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue