From 8a48862adc2958fb7f057783919b00580d26bb6c Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Thu, 8 Aug 2019 09:26:16 +0200 Subject: [PATCH] Use a slightly more aggressive backoff approach Doubling the backoff every iteration turned out to be a bit too relaxed for the common situations where you run into API throttling. This change gives the API enough room to breathe, but re-tries requests just a little more often. --- mastodon.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mastodon.go b/mastodon.go index d0a94d4..d9c7883 100644 --- a/mastodon.go +++ b/mastodon.go @@ -123,7 +123,7 @@ func (c *Client) doAPI(ctx context.Context, method string, uri string, params in } var resp *http.Response - backoff := 1000 * time.Millisecond + backoff := time.Second for { resp, err = c.Do(req) if err != nil { @@ -137,13 +137,14 @@ func (c *Client) doAPI(ctx context.Context, method string, uri string, params in if backoff > time.Hour { break } - backoff *= 2 select { case <-time.After(backoff): case <-ctx.Done(): return ctx.Err() } + + backoff = time.Duration(1.5 * float64(backoff)) continue } break