From df559f3042539675f567b225979b957ab749b075 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Tue, 6 Nov 2018 13:24:48 +0100 Subject: [PATCH] logger: unlock the mutex for fsync & call fsync only when backend is running - fsync can be a long blocking operation, so we need to make sure the main logger thread does not block during this time, when it tries to aquire the mutex - fixes calling fsync on an invalid file descriptor --- src/modules/logger/log_writer_file.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/modules/logger/log_writer_file.cpp b/src/modules/logger/log_writer_file.cpp index 24095a3738..a2c09fbc7f 100644 --- a/src/modules/logger/log_writer_file.cpp +++ b/src/modules/logger/log_writer_file.cpp @@ -257,8 +257,10 @@ void LogWriterFile::run() buffer.close_file(); } - } else if (call_fsync) { + } else if (call_fsync && buffer._should_run) { + pthread_mutex_unlock(&_mtx); buffer.fsync(); + pthread_mutex_lock(&_mtx); } else if (available == 0 && !buffer._should_run) { buffer.close_file();