From 582a0a57ce1c520c21cc9901a0c77214a416a6cc Mon Sep 17 00:00:00 2001 From: raldone01 Date: Thu, 6 Jun 2024 09:46:37 +0200 Subject: [PATCH] Fix: `DirSink` could drop logs if the mutex was locked while logging. --- funcs/logger.gd | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/funcs/logger.gd b/funcs/logger.gd index f4ff9ab..7b2b665 100644 --- a/funcs/logger.gd +++ b/funcs/logger.gd @@ -363,7 +363,9 @@ class DirSink extends LogSink: _io_thread_current_file.close() func write_bulks(p_log_records: Array[Dictionary], p_formatted_messages: PackedStringArray) -> void: - if _io_thread_log_lock.try_lock(): + # If this causes lag spikes this can be replaced with a try_lock but a second buffer is needed to avoid dropping logs. + # Also if this is ever implemented flush_buffer() would have to use lock and ensure all data is sent to the thread. + if _io_thread_log_lock.lock(): _io_thread_formatted_messages.append_array(p_formatted_messages) _io_thread_log_lock.unlock() _io_thread_work_semaphore.post()