From fe0b540096262c3a71a38cadec77419193d8bc3e Mon Sep 17 00:00:00 2001 From: abicky Date: Tue, 15 Dec 2020 03:24:04 +0900 Subject: [PATCH] Prevent retry.step from being called too many times in a short time This commit resolves https://github.com/fluent/fluentd/issues/2123 by avoiding the situation when @retry.step is called almost as many times as the number of flush threads in a short time. --- lib/fluent/plugin/output.rb | 8 +++++++- lib/fluent/plugin_helper/retry_state.rb | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/fluent/plugin/output.rb b/lib/fluent/plugin/output.rb index 93adeed9b8..9fda748559 100644 --- a/lib/fluent/plugin/output.rb +++ b/lib/fluent/plugin/output.rb @@ -1251,7 +1251,13 @@ def update_retry_state(chunk_id, using_secondary, error = nil) log.debug "buffer queue cleared" @retry = nil else - @retry.step + # Ensure that the current time is greater than or equal to @retry.next_time to avoid the situation when + # @retry.step is called almost as many times as the number of flush threads in a short time. + if Time.now >= @retry.next_time + @retry.step + else + @retry.recalc_next_time + end if error if using_secondary msg = "failed to flush the buffer with secondary output." diff --git a/lib/fluent/plugin_helper/retry_state.rb b/lib/fluent/plugin_helper/retry_state.rb index d8d629afef..687e8052f3 100644 --- a/lib/fluent/plugin_helper/retry_state.rb +++ b/lib/fluent/plugin_helper/retry_state.rb @@ -127,6 +127,10 @@ def step nil end + def recalc_next_time + @next_time = calc_next_time + end + def limit? if @forever false