From 990cbea50dcec97774d75432d08e702f4c0888da Mon Sep 17 00:00:00 2001 From: abicky Date: Mon, 23 Oct 2017 15:45:07 +0900 Subject: [PATCH] Lock the buffer during selecting metadata cf. https://github.com/fluent/fluentd/pull/1721#discussion_r146176074 --- lib/fluent/plugin/buffer.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/fluent/plugin/buffer.rb b/lib/fluent/plugin/buffer.rb index 337b3b79c8..61a904eda6 100644 --- a/lib/fluent/plugin/buffer.rb +++ b/lib/fluent/plugin/buffer.rb @@ -351,11 +351,15 @@ def enqueue_unstaged_chunk(chunk) def enqueue_all log.trace "enqueueing all chunks in buffer", instance: self.object_id if block_given? - synchronize{ @stage.keys }.each do |metadata| - chunk = @stage[metadata] - next unless chunk - v = yield metadata, chunk - enqueue_chunk(metadata) if v + metadata_array = [] + synchronize do + @stage.each do |metadata, chunk| + v = yield metadata, chunk + metadata_array << metadata if v + end + end + metadata_array.each do |metadata| + enqueue_chunk(metadata) end else synchronize{ @stage.keys }.each do |metadata|