From 623c8f0d3731a1f2ca7336c2e11150fa65404711 Mon Sep 17 00:00:00 2001 From: Geoff Greer Date: Fri, 13 Sep 2024 00:06:54 -0700 Subject: [PATCH] Skip using rate limit info if it doesn't make sense. (#227) --- pkg/sync/syncer.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/sync/syncer.go b/pkg/sync/syncer.go index 9d413805..18c737a8 100644 --- a/pkg/sync/syncer.go +++ b/pkg/sync/syncer.go @@ -109,15 +109,19 @@ func shouldWaitAndRetry(ctx context.Context, err error) bool { for _, detail := range details { if rlData, ok := detail.(*v2.RateLimitDescription); ok { waitResetAt := time.Until(rlData.ResetAt.AsTime()) + if waitResetAt <= 0 { + continue + } duration := time.Duration(rlData.Limit) - if duration == 0 { - duration = 1 + if duration <= 0 { + continue } waitResetAt /= duration // Round up to the nearest second to make sure we don't hit the rate limit again waitResetAt = time.Duration(math.Ceil(waitResetAt.Seconds())) * time.Second if waitResetAt > 0 { wait = waitResetAt + break } } }