From d14b4e71f80227bc193a28e0f50c6ee007f3d050 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Thu, 18 Jan 2018 02:36:27 +0100 Subject: Restart only up to five times due to mem leaks --- README.md | 7 ++++--- src/odr-audioenc.cpp | 28 +++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9c6758c..73b06ed 100644 --- a/README.md +++ b/README.md @@ -185,9 +185,10 @@ odr-audioenc returns: * 4 it the ZeroMQ send failed * 5 if the input had a fault -You can use the *-R* option to get ODR-AudioEnc to restart the input automatically after -a fault. This does not guarantee that the odr-audioenc process will never die, and running -it under a process supervisor is encouraged regardless of this feature being enabled or not. +You can use the *-R* option to get ODR-AudioEnc to restart the input +automatically up to five times after a fault. As this does not guarantee that +the odr-audioenc process will never die, running it under a process supervisor +is recommended regardless of this feature being enabled or not. Known Limitations diff --git a/src/odr-audioenc.cpp b/src/odr-audioenc.cpp index 7ad2222..9053eec 100644 --- a/src/odr-audioenc.cpp +++ b/src/odr-audioenc.cpp @@ -1,6 +1,6 @@ /* ------------------------------------------------------------------ * Copyright (C) 2011 Martin Storsjo - * Copyright (C) 2017 Matthias P. Braendli + * Copyright (C) 2018 Matthias P. Braendli * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -85,6 +85,10 @@ extern "C" { #include "libtoolame-dab/toolame.h" } +/* Due to memory leaks in the VLC input, + * we don't want to restart it endlessly. */ +constexpr int MAX_FAULTS_ALLOWED = 5; + using vec_u8 = std::vector; //! Enumeration of encoders we can use @@ -218,7 +222,7 @@ void usage(const char* name) " (default: /tmp/pad.fifo).\n" " -l, --level Show peak audio level indication.\n" " -s, --silence=TIMEOUT Abort encoding after TIMEOUT seconds of silence.\n" - " -R, --restart Automatically restart input on fault.\n" + " -R, --restart Automatically restart input on fault, up to five times.\n" "\n" "Only the tcp:// zeromq transport has been tested until now,\n" " but epgm://, pgm:// and ipc:// are also accepted\n" @@ -460,6 +464,7 @@ int main(int argc, char *argv[]) audioenc_settings_t settings; bool restart_on_fault = false; + int fault_counter = 0; int bitrate = 0; // 0 is default int ch=0; @@ -1038,12 +1043,21 @@ int main(int argc, char *argv[]) fprintf(stderr, "Detected fault in input!\n"); if (restart_on_fault) { + fault_counter++; + + if (fault_counter >= MAX_FAULTS_ALLOWED) { + fprintf(stderr, "Maximum number of input faults reached, aborting"); + retval = 5; + break; + } + try { input = initialise_input(settings, queue); } catch (const runtime_error& e) { fprintf(stderr, "Initialising input triggered exception: %s\n", e.what()); - return 1; + retval = 5; + break; } continue; @@ -1090,6 +1104,14 @@ int main(int argc, char *argv[]) fprintf(stderr, "Detected fault in input! No data in time.\n"); if (restart_on_fault) { + fault_counter++; + + if (fault_counter >= MAX_FAULTS_ALLOWED) { + fprintf(stderr, "Maximum number of input faults reached, aborting"); + retval = 5; + break; + } + try { input = initialise_input(settings, queue); } -- cgit v1.2.3