From 22c2dfdbd22aa2b0586e32592beb0d24d1925b59 Mon Sep 17 00:00:00 2001 From: Yuta Iwama Date: Tue, 9 Jul 2019 12:21:38 +0900 Subject: [PATCH] Avoid zero division error when there are no available nodes Signed-off-by: Yuta Iwama --- lib/fluent/plugin/out_forward.rb | 6 ++++++ test/plugin/test_out_forward.rb | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/fluent/plugin/out_forward.rb b/lib/fluent/plugin/out_forward.rb index 53edec4461..684a2484cc 100644 --- a/lib/fluent/plugin/out_forward.rb +++ b/lib/fluent/plugin/out_forward.rb @@ -428,6 +428,12 @@ def rebuild_weight_array end weight_array = [] + if regular_nodes.empty? + log.warn('No nodes are available') + @weight_array = weight_array + return @weight_array + end + gcd = regular_nodes.map {|n| n.weight }.inject(0) {|r,w| r.gcd(w) } regular_nodes.each {|n| (n.weight / gcd).times { diff --git a/test/plugin/test_out_forward.rb b/test/plugin/test_out_forward.rb index 896429da74..9ffba3ec20 100644 --- a/test/plugin/test_out_forward.rb +++ b/test/plugin/test_out_forward.rb @@ -1010,6 +1010,20 @@ def create_target_input_driver(response_stub: nil, disconnect: false, conf: TARG end end + test 'if no available node' do + # do not create output driver + d = create_driver(%[ + + name test + standby + host #{TARGET_HOST} + port #{TARGET_PORT} + + ]) + d.instance_start + assert_nothing_raised { d.run } + end + sub_test_case 'keepalive' do test 'Do not create connection per send_data' do target_input_driver = create_target_input_driver(conf: TARGET_CONFIG)