From d7a9b123e6b84df4a7c01daaac64706c39abd3d7 Mon Sep 17 00:00:00 2001 From: Dusan Zivkovic Date: Fri, 6 Mar 2020 11:52:54 +0100 Subject: [PATCH] logger: fix thread deadlock --- src/modules/logger/log_writer_file.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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