summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authormo <mo@mokhan.ca>2018-11-10 19:39:33 -0700
committermo <mo@mokhan.ca>2018-11-10 19:39:33 -0700
commitdc612620ab4b9704519e37aa168c5c2d9c083bd1 (patch)
tree483e2de36e85dd7c0a8efc2001717e4d88f14872 /lib
parent2edc66973dcf57122f6e6e2956e4f9ee66167152 (diff)
fix off by one on retry logic.
Diffstat (limited to 'lib')
-rw-r--r--lib/net/hippie/client.rb4
-rw-r--r--lib/net/hippie/version.rb2
2 files changed, 3 insertions, 3 deletions
diff --git a/lib/net/hippie/client.rb b/lib/net/hippie/client.rb
index 0c94e4a..edd31ba 100644
--- a/lib/net/hippie/client.rb
+++ b/lib/net/hippie/client.rb
@@ -71,11 +71,11 @@ module Net
# attempt 7 -> delay 64 second
# attempt 8 -> delay 128 second
def with_retry(retries: 3)
- retries = 3 if retries <= 0
+ retries = 0 if retries.nil? || retries.negative?
0.upto(retries) do |n|
return yield self
rescue *::Net::Hippie::CONNECTION_ERRORS => error
- raise error if n >= retries
+ raise error if n == retries
delay = (2**n) + rand(0.5) # delay + jitter
warn("`#{error.message}` Retry: #{n + 1}/#{retries} Delay: #{delay}s")
diff --git a/lib/net/hippie/version.rb b/lib/net/hippie/version.rb
index 71b849e..3c78850 100644
--- a/lib/net/hippie/version.rb
+++ b/lib/net/hippie/version.rb
@@ -2,6 +2,6 @@
module Net
module Hippie
- VERSION = '0.2.0'
+ VERSION = '0.2.1'
end
end