Handle ECONNREFUSED and typo fix#113
Conversation
| retries ||= 1 | ||
| if retries <= 1 && boom.is_a?(Errno::ENOTCONN) or | ||
| retries <= 1 && boom.is_a?(Errno::ECONNREFUSED) or | ||
| retries <= 1 && boom.is_a?(IOError) && boom.message =~ /closed stream/i |
There was a problem hiding this comment.
Nit: now that we have three cases, we could refactor this condition like that:
if retries <= 1 &&
(boom.is_a?(Errno::ENOTCONN) or
boom.is_a?(Errno::ECONNREFUSED) or
boom.is_a?(IOError) && boom.message =~ /closed stream/i)
There was a problem hiding this comment.
Sure thing - added refactor and unit test. Thanks for your patience, was offline last couple weeks.
Oddly I was seeing these test failures - not sure if it's my environment:
1) Failure:
Datadog::Statsd::GC#test_0001_produces low amounts of garbage for simple methods [/Users/fmoyer/Code/dogstatsd-ruby/spec/statsd_spec.rb:1047]:
sourcefile sourceline class count
------------------------------------------------------- ---------- ------ -----
/Users/fmoyer/Code/dogstatsd-ruby/spec/helper.rb 23 Array 1
/Users/fmoyer/Code/dogstatsd-ruby/lib/datadog/statsd.rb 88 Array 1
/Users/fmoyer/Code/dogstatsd-ruby/lib/datadog/statsd.rb 578 String 1
/Users/fmoyer/Code/dogstatsd-ruby/lib/datadog/statsd.rb 571 String 1
/Users/fmoyer/Code/dogstatsd-ruby/lib/datadog/statsd.rb 568 String 1.
Expected: 6
Actual: 5
2) Failure:
Datadog::Statsd::GC#test_0002_produces low amounts of garbage for timing [/Users/fmoyer/Code/dogstatsd-ruby/spec/statsd_spec.rb:1051]:
sourcefile sourceline class count
------------------------------------------------------- ---------- ------ -----
/Users/fmoyer/Code/dogstatsd-ruby/spec/helper.rb 23 Array 1
/Users/fmoyer/Code/dogstatsd-ruby/lib/datadog/statsd.rb 88 Array 1
/Users/fmoyer/Code/dogstatsd-ruby/lib/datadog/statsd.rb 578 String 1
/Users/fmoyer/Code/dogstatsd-ruby/lib/datadog/statsd.rb 571 String 1
/Users/fmoyer/Code/dogstatsd-ruby/lib/datadog/statsd.rb 568 String 1.
Expected: 6
Actual: 5
There was a problem hiding this comment.
Yeah, this is strange, seems like there's one allocation that's not done on line 87 (88 in your output).
The CI tests passed, and I tested locally your fork with success, so that may be due to a specific environment.
I'll keep this in mind, but it shouldn't block this PR.
If the problem persists on your environment, could you create an issue so that we can keep track of it?
|
Sure thing, feel free to merge when ready. |
This PR adds error handling for
ECONNREFUSED, and also fixes a small typo. This allows requests that fail due to a previous request encountering ECONNREFUSED to retry if the service on 8125 is available. Small edge case.