Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calc_retry_wait is broken if Integer is used for retry_wait #529

Merged
merged 1 commit into from
Jan 12, 2015

Conversation

sabottenda
Copy link
Contributor

From v0.10.58 or later and v0.12, calc_retry_wait causes an exception if Integer is used for retry_wait.
retry_wait is time type, so it can be Integer value. #finite? is a method for Float class, not for Integer.

@sonots
Copy link
Member

sonots commented Dec 29, 2014

👍

@kiyoto kiyoto added the bug label Jan 3, 2015
@mr-salty
Copy link
Contributor

mr-salty commented Jan 5, 2015

Hi - sorry abot this - it was due to my PR #502 although it appears my test didn't catch this problem - could you add a test that fails without this change?

Also, I believe a similar problem to the one I was trying to solve remains - even though 'wait' will not overflow if it is an Integer, the +/- 12.5% calculation on line 410 converts it to float, which can produce NaN and lead to an exception on 412.

So, probably the cleanest fix would be to do the 12.5% retry_wait calculation unconditionally and then check finite? or nan? on the result (which is always a float).

@repeatedly repeatedly self-assigned this Jan 6, 2015
@repeatedly
Copy link
Member

Converting retry_wait to Float type in configure seems better than wait.is_a?(Float).
retry_wait is smaller so embbeded float is used on 64bit environment.

From mr-salty comment, adding test is best.

calc_retry_wait is broken if Integer is used for retry_wait
@sabottenda
Copy link
Contributor Author

Converting retry_wait to Float type in configure seems better than wait.is_a?(Float).

thanks, it's better.

Also, I believe a similar problem to the one I was trying to solve remains - even though 'wait' will not overflow if it is an Integer, the +/- 12.5% calculation on line 410 converts it to float, which can produce NaN and lead to an exception on 412.

@mr-salty I can't find the case to produce NaN. Please tell me the case.

Anyway, I reverted calc_retry_wait and just convert to Float in configure. Please check it.

repeatedly added a commit that referenced this pull request Jan 12, 2015
calc_retry_wait is broken if Integer is used for retry_wait
@repeatedly repeatedly merged commit 8fcc653 into fluent:master Jan 12, 2015
@repeatedly
Copy link
Member

Code seems good so I merged this patch for new release.

@mr-salty
Copy link
Contributor

Hi, @sabottenda - sorry i didn't address your comment before merge but it looks ok to me and I also tested it.

test_large_num_retries is the one that produces the error, so I added 'retry_wait 1s' to the config there and verified that it fails without your change and passes with it. Thanks for taking care of this!

@sonots
Copy link
Member

sonots commented Jan 13, 2015

Test fails like

===============================================================================
Error: test_calc_retry_wait_with_integer_retry_wait(FluentOutputTest::BufferedOutputTest)
: NoMethodError: undefined method `finite?' for 131072:Fixnum
/Users/seo.naotoshi/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/fluentd-0.12.2/lib/fluent/output.rb:407:in `calc_retry_wait'
test/test_output.rb:87:in `test_calc_retry_wait_with_integer_retry_wait'
     84:       d.instance.retry_limit.times {
     85:         d.instance.instance_eval { @num_errors += 1 }
     86:       }
  => 87:       assert_equal true, d.instance.calc_retry_wait.finite?
     88:     end
     89:
     90:     def test_large_num_retries
===============================================================================
F
===============================================================================
Failure:
test_configure(FluentOutputTest::BufferedOutputTest)
test/test_output.rb:61:in `test_configure'
     58:
     59:       # retry_wait is converted to Float for calc_retry_wait
     60:       d = create_driver(CONFIG + %[retry_wait 1s])
  => 61:       assert_equal Float, d.instance.retry_wait.class
     62:     end
     63:
     64:     def test_calc_retry_wait
<Float> expected but was
<Fixnum>

@repeatedly
Copy link
Member

Maybe, it seems your environment problem. Tests are passed on Travis-CI.

https://travis-ci.org/fluent/fluentd/builds/46752070

@sonots
Copy link
Member

sonots commented Jan 13, 2015

Ah, got it, passed. Sorry for making worry about this.

repeatedly added a commit that referenced this pull request Jan 15, 2015
calc_retry_wait is broken if Integer is used for retry_wait
@sonots sonots added the v0.10 label Jan 15, 2015
@sonots
Copy link
Member

sonots commented Jan 15, 2015

cherry-picked to v0.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants