From 1a6f16b4c2c06060c65837c1167d055ec93bded5 Mon Sep 17 00:00:00 2001 From: abicky Date: Fri, 20 Oct 2017 18:34:42 +0900 Subject: [PATCH] Process chunks with buffer lock in enqueue_chunk In flush threads @buffer could call destructive methods of chunks in @queue without chunk lock, so buffer lock is required. --- lib/fluent/plugin/buffer.rb | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/fluent/plugin/buffer.rb b/lib/fluent/plugin/buffer.rb index f62e92a713..337b3b79c8 100644 --- a/lib/fluent/plugin/buffer.rb +++ b/lib/fluent/plugin/buffer.rb @@ -319,21 +319,19 @@ def enqueue_chunk(metadata) return nil unless chunk chunk.synchronize do - if chunk.empty? - chunk.close - else - synchronize do + synchronize do + if chunk.empty? + chunk.close + else @queue << chunk @queued_num[metadata] = @queued_num.fetch(metadata, 0) + 1 + chunk.enqueued! end - chunk.enqueued! + bytesize = chunk.bytesize + @stage_size -= bytesize + @queue_size += bytesize end end - bytesize = chunk.bytesize - synchronize do - @stage_size -= bytesize - @queue_size += bytesize - end nil end