aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/github/client.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2022-11-15 20:05:04 +0100
committerMichael Muré <batolettre@gmail.com>2022-11-15 20:05:04 +0100
commit9abeb9956b7519ef5e67fed48093ebfbb3868b2f (patch)
tree2822b547bb4947b73e308c02b0764d7144c1dcbd /bridge/github/client.go
parent733c7c6b3ebe1fb322d8107fdf6dae7a6060b87b (diff)
downloadgit-bug-9abeb9956b7519ef5e67fed48093ebfbb3868b2f.tar.gz
github: sanitize rate limit waiting time
In particular, for the case of when the local clock is wrong, but also if the returned value is bogus.
Diffstat (limited to 'bridge/github/client.go')
-rw-r--r--bridge/github/client.go13
1 files changed, 11 insertions, 2 deletions
diff --git a/bridge/github/client.go b/bridge/github/client.go
index 57c8646a..361d0ee5 100644
--- a/bridge/github/client.go
+++ b/bridge/github/client.go
@@ -87,7 +87,7 @@ func (c *rateLimitHandlerClient) queryPrintMsgs(ctx context.Context, query inter
return c.callAPIAndRetry(ctx, queryFun, callback)
}
-// callAPIAndRetry calls the Github GraphQL API (inderectely through callAPIDealWithLimit) and in
+// callAPIAndRetry calls the Github GraphQL API (indirectly through callAPIDealWithLimit) and in
// case of error it repeats the request to the Github API. The parameter `apiCall` is intended to be
// a closure containing a query or a mutation to the Github GraphQL API.
func (c *rateLimitHandlerClient) callAPIAndRetry(ctx context.Context, apiCall func(context.Context) error, rateLimitEvent func(msg string)) error {
@@ -149,8 +149,17 @@ func (c *rateLimitHandlerClient) callAPIDealWithLimit(ctx context.Context, apiCa
// Send message about rate limiting event.
rateLimitCallback(msg)
+ // sanitize the reset time, in case the local clock is wrong
+ waitTime := time.Until(resetTime)
+ if waitTime < 0 {
+ waitTime = 10 * time.Second
+ }
+ if waitTime > 30*time.Second {
+ waitTime = 30 * time.Second
+ }
+
// Pause current goroutine
- timer := time.NewTimer(time.Until(resetTime))
+ timer := time.NewTimer(waitTime)
select {
case <-ctx.Done():
stop(timer)