taoensso / encore

Core utils library for Clojure/Script
https://www.taoensso.com/encore
Eclipse Public License 1.0
272 stars 53 forks source link

Make sure exponential backoff does not exceed Long range. #27

Closed xsc closed 8 years ago

xsc commented 8 years ago

An exception is thrown when calling exp-backoff with higher nattempt, e.g.:

(taoensso.encore/exp-backoff 64 {:max 10000})
;; IllegalArgumentException Value out of range for long: 7.864640105381429E21

(taoensso.encore/exp-backoff 1024 {:max 10000})
;; IllegalArgumentException Value out of range for long: Infinity

This fixes the issue by ensuring that the result, before applying :min and :max, does not exceed Long/MAX_VALUE.

xsc commented 8 years ago

Hold on, this might break the ClojureScript version (since Long/MAX_VALUE is not available).

ptaoussanis commented 8 years ago

Hi Yannick,

How's this?: https://github.com/ptaoussanis/encore/commit/aecdb2c061ba3005c63de278ab7626ba33890792

Calls with larger n's shouldn't generally occur in realistic situations since the backoff quickly approaches infinity.

xsc commented 8 years ago

LGTM, thanks!