HomePhorge
Diffusion tesla 7b3a8ae5f563

Make sure retry won't crash when either `delay` or `max_delay` are misconfigured

Description

Make sure retry won't crash when either delay or max_delay are misconfigured

When delay or max_delay are less than 1, the Retry middleware currently crashes with
the following error:

  • (FunctionClauseError) no function clause matching in :rand.uniform_s/2 (stdlib 3.13) rand.erl:326: :rand.uniform_s/2 (stdlib 3.13) rand.erl:299: :rand.uniform/1 (tesla 1.3.3) lib/tesla/middleware/retry.ex:106: Tesla.Middleware.Retry.backoff/3 (tesla 1.3.3) lib/tesla/middleware/retry.ex:94: Tesla.Middleware.Retry.retry/3

It happens because :rand.uniform/1 requires a positive integer:

https://erlang.org/doc/man/rand.html#uniform-1

This change adjusts max_delay to 1 when it isn't positive and also adjusts
delay to make sure it is positive and smaller than max_delay.

Details

Provenance
João BrittoAuthored on Aug 3 2020, 3:09 PM
Parents
R28:31b23fbaa7d1: Optimize backoff factor calculation
Branches
Unknown
Tags
Unknown

Event Timeline