Open Jamie0 opened 2 years ago
Having dug a bit deeper into the code there definitely seems to be a fundamental issue with flushing error/warning logs to stderr.
It seems the issue is caused by the logs never being flushed from memory. A worker thread calls log_write, but as the main thread never logs any type of error, the warnings persist in memory waiting to be flushed indefinitely. We are successfully working around this by reducing the logging level from 2 to 1.
just trying to get a handle on this. I'm trying a stderr output and even forcing extra warning messages to cause a leak and it just had the default 100 lines internally. Besides the - error log and level 2.
I'm also interested in the trigger for the message in question. Do you have a stream that shows it?
Closing as unfortuntely I'm not able to reproduce this at all. For context, this issue affected one or two customers at a commercial streaming provider and I could reproduce it before by re-casting their stream (without reencoding) to a test server. Trying again on those same streams no longer seems to cause the leak (and Valgrind doesn't report those leaks) so I think something must have been up with their encoding client generating bad or wrongly padded frames. Nonetheless it's odd that the logs didn't flush and stayed in memory when it happened, so if I spot it again I'll reopen the issue with hopefully more info.
I've managed to run into this again, and indeed the valgrind result from last time was a bit of a red herring.
We run icecast-kh under supervisord (using some code that was forked from AzuraCast before they relicensed), and its configured to write its error logs to /dev/stderr, which is a symlink of /proc/fd/self/2.
If we instead log to a normal file, the issue goes away.
Having a peek in log.c/log_write (in the now slightly old version we're running), the code that frees old logs doesn't run if the log file size doesn't grow.
This code isn't present in the main branch any more, but I can see there is still a call to fstat on the log files, so I'm tentatively re-opening the issue
I've observed that, when streaming to a mount point in HE-AAC format, icecast-kh leaks memory. Roughly every minute, 250-260k of memory is leaked.
The culprit seems to be the call to WARN3 in validate_mpeg on line 944. Commenting out this line and recompiling plugs the leak. Seemingly the log entry is not correctly written to stderr so the entry's memory is never freed.
I've included the result of running valgrind with
--leak-check=full --leak-resolution=high --num-callers=20