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