From 28cc886938218a90dc6589968a9df060e9ec6fd2 Mon Sep 17 00:00:00 2001 From: Takuro Ashie Date: Tue, 24 May 2022 13:33:10 +0900 Subject: [PATCH] output: Fix a potential crash bug of flush thread Because `@output_flush_thread_current_position` isn't initialize before starting flush threads, it might cause crash when flush threads start to processing buffers before initializing it at main thread. Fixes #3718 Signed-off-by: Takuro Ashie --- lib/fluent/plugin/output.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/fluent/plugin/output.rb b/lib/fluent/plugin/output.rb index 976ff1002c..9087994bc9 100644 --- a/lib/fluent/plugin/output.rb +++ b/lib/fluent/plugin/output.rb @@ -235,6 +235,7 @@ def initialize @dequeued_chunks_mutex = nil @output_enqueue_thread = nil @output_flush_threads = nil + @output_flush_thread_current_position = 0 @simple_chunking = nil @chunk_keys = @chunk_key_accessors = @chunk_key_time = @chunk_key_tag = nil @@ -492,6 +493,7 @@ def start @dequeued_chunks = [] @dequeued_chunks_mutex = Mutex.new + @output_flush_thread_current_position = 0 @buffer_config.flush_thread_count.times do |i| thread_title = "flush_thread_#{i}".to_sym thread_state = FlushThreadState.new(nil, nil, Mutex.new, ConditionVariable.new) @@ -503,7 +505,6 @@ def start @output_flush_threads << thread_state end end - @output_flush_thread_current_position = 0 if !@under_plugin_development && (@flush_mode == :interval || @chunk_key_time) @output_enqueue_thread = thread_create(:enqueue_thread, &method(:enqueue_thread_run))