From 00a5cc185da2bf8a980764aad213f0fd885a8bf6 Mon Sep 17 00:00:00 2001 From: Takuro Ashie Date: Wed, 23 Feb 2022 00:02:09 +0900 Subject: [PATCH] Fix wrong calculation of max retry timeout for exponential backoff Exponents should be started with 0, not -1. Signed-off-by: Takuro Ashie --- lib/fluent/plugin_helper/retry_state.rb | 2 +- test/plugin_helper/test_retry_state.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/fluent/plugin_helper/retry_state.rb b/lib/fluent/plugin_helper/retry_state.rb index 687e8052f3..7851fd61ea 100644 --- a/lib/fluent/plugin_helper/retry_state.rb +++ b/lib/fluent/plugin_helper/retry_state.rb @@ -159,7 +159,7 @@ def naive_next_time(retry_next_times) def calc_max_retry_timeout(max_steps) result = 0 max_steps.times { |i| - result += calc_interval(i) + result += calc_interval(i + 1) } result end diff --git a/test/plugin_helper/test_retry_state.rb b/test/plugin_helper/test_retry_state.rb index 616cc8671d..4edd41bdf9 100644 --- a/test/plugin_helper/test_retry_state.rb +++ b/test/plugin_helper/test_retry_state.rb @@ -413,7 +413,7 @@ class Dummy < Fluent::Plugin::TestBase override_current_time(s, dummy_current_time) timeout = 0 - 5.times { |i| timeout += 1.0 * (2 ** (i - 1)) } + 5.times { |i| timeout += 1.0 * (2 ** i) } assert_equal dummy_current_time, s.current_time assert_equal (dummy_current_time + 100), s.timeout_at