tvhlog: ensure the logging Q is bounded in size, else it can become a leak
If processing because so high that the log queue becomes swamped we can end up with a sort of avalanche scenario where everything gradually slows down and the size of the buffer continues to grow. The main culprits of this have been eliminated at source, however this is still a useful safe guard.
This commit is contained in:
parent
709f86057d
commit
c83c5eb917
1 changed files with 24 additions and 1 deletions
25
src/tvhlog.c
25
src/tvhlog.c
|
@ -35,6 +35,10 @@ pthread_t tvhlog_tid;
|
|||
pthread_mutex_t tvhlog_mutex;
|
||||
pthread_cond_t tvhlog_cond;
|
||||
TAILQ_HEAD(,tvhlog_msg) tvhlog_queue;
|
||||
int tvhlog_queue_size;
|
||||
int tvhlog_queue_full;
|
||||
|
||||
#define TVHLOG_QUEUE_MAXSIZE 10000
|
||||
|
||||
typedef struct tvhlog_msg
|
||||
{
|
||||
|
@ -165,6 +169,9 @@ tvhlog_thread ( void *p )
|
|||
continue;
|
||||
}
|
||||
TAILQ_REMOVE(&tvhlog_queue, msg, link);
|
||||
tvhlog_queue_size--;
|
||||
if (tvhlog_queue_size < (TVHLOG_QUEUE_MAXSIZE / 2))
|
||||
tvhlog_queue_full = 0;
|
||||
|
||||
/* Copy options and path */
|
||||
if (!fp) {
|
||||
|
@ -244,8 +251,15 @@ void tvhlogv ( const char *file, int line,
|
|||
size_t l;
|
||||
char buf[1024];
|
||||
|
||||
/* Check debug enabled (and cache config) */
|
||||
pthread_mutex_lock(&tvhlog_mutex);
|
||||
|
||||
/* Check for full */
|
||||
if (tvhlog_queue_full) {
|
||||
pthread_mutex_unlock(&tvhlog_mutex);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Check debug enabled (and cache config) */
|
||||
options = tvhlog_options;
|
||||
if (severity >= LOG_DEBUG) {
|
||||
ok = 0;
|
||||
|
@ -271,6 +285,14 @@ void tvhlogv ( const char *file, int line,
|
|||
return;
|
||||
}
|
||||
|
||||
/* FULL */
|
||||
if (tvhlog_queue_size == TVHLOG_QUEUE_MAXSIZE) {
|
||||
tvhlog_queue_full = 1;
|
||||
fmt = "log buffer full";
|
||||
args = NULL;
|
||||
severity = LOG_ERR;
|
||||
}
|
||||
|
||||
/* Basic message */
|
||||
l = 0;
|
||||
if (options & TVHLOG_OPT_THREAD) {
|
||||
|
@ -291,6 +313,7 @@ void tvhlogv ( const char *file, int line,
|
|||
msg->severity = severity;
|
||||
msg->notify = notify;
|
||||
TAILQ_INSERT_TAIL(&tvhlog_queue, msg, link);
|
||||
tvhlog_queue_size++;
|
||||
pthread_cond_signal(&tvhlog_cond);
|
||||
pthread_mutex_unlock(&tvhlog_mutex);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue