diff --git a/src/modules/logger/log_writer_file.cpp b/src/modules/logger/log_writer_file.cpp index 8f401ce505..d6f52182a3 100644 --- a/src/modules/logger/log_writer_file.cpp +++ b/src/modules/logger/log_writer_file.cpp @@ -295,8 +295,12 @@ void LogWriterFile::run() /* Wait for a call to notify(), which indicates new data is available. * Note that at this point there could already be new data available (because of a longer write), * and calling pthread_cond_wait() will still wait for the next notify(). But this is generally - * not an issue because notify() is called regularly. */ - pthread_cond_wait(&_cv, &_mtx); + * not an issue because notify() is called regularly. + * If the logger was switched off in the meantime, do not wait for data, instead run this loop + * once more to write remaining data and close the file. */ + if (_buffers[0]._should_run) { + pthread_cond_wait(&_cv, &_mtx); + } } // go back to idle