Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

github: GetIssues loops indefinitely if request fails #255

Open
joshuasing opened this issue Aug 15, 2024 · 2 comments
Open

github: GetIssues loops indefinitely if request fails #255

joshuasing opened this issue Aug 15, 2024 · 2 comments

Comments

@joshuasing
Copy link

joshuasing commented Aug 15, 2024

The github.GetIssues function contains a for loop to handle issue pagination:

gickup/github/github.go

Lines 388 to 402 in d29454e

for {
i, _, err := client.Issues.ListByRepo(context.Background(), *repo.Owner.Login, *repo.Name, listOptions)
if err != nil {
sub.Error().Err(err).Str("repo", *repo.Name).Msg("can't fetch issues")
} else {
if len(i) > 0 {
for _, issue := range i {
issues[strconv.Itoa(*issue.Number)] = issue
}
} else {
break
}
listOptions.Page++
}
}

However, when the request fails, instead of exiting or handling the error, it is logged and immediately retried.
The retry happens without delay, and happens indefinitely or until the request succeeds.

When a permanent error occurs when getting issues, such as 403 Resource not accessible by personal access token [], this will loop indefinitely, resulting in the GitHub API being spammed and causing the account to be rate limited.

Instead of indefinitely retrying, there should be an errCount or similar variable that makes the function exit after a certain number of retries. It would also be nice if request were retried after a delay, with jitter. Ideally, the function would also return the error, however that would be an API breaking change.

This error made it near impossible to use my GitHub account for several days, as it was constantly rate limited and impossible to tell what was causing the rate limit to be hit. I am thankful that GitHub did not terminate my account for the amount of API requests that were being made.

@cooperspencer
Copy link
Owner

I'll have a look at it when I have access to my laptop again.

@cooperspencer
Copy link
Owner

I finally have access to my laptop again.
https://github.com/cooperspencer/gickup/pull/256/files

Gickup will attempt to retrieve the issues up to five times. If it still fails, it will return the list of issues it has managed to collect so far. I added a special case for a 403 error, as it doesn't make sense to retry when permissions are lacking. In this case, it will try once, throw an error, and then continue with the backup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants