fix: add retries to GitHub client for GetModifiedFiles on 404 #2013
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a follow on to resolve similar issues to #1019.
In #1131 retries were added to GetPullRequest. And in #1810 a backoff was included.
However, those only resolve one potential request at the very beginning of a PR creation. The other request that happens early on during auto-plan is one to ListFiles to detect the modified files. This too can sometimes result in a 404 due to async updates on the GitHub side.
My team recently upgraded a few Atlantis instances that were pretty old. They didn't yet include the fixes described above.
We upgraded to v0.18.1. After upgrading we were hopeful our dev teams would be happy to know these race condition errors were a thing of the past. But in only a couple of days, we got another report!
I was able to find an error log with the following message (org/repo/pr-number redacted):
And the following stacktrace:
The fixes for #1019 added retries for the
/repos/{owner}/{repo}/pulls
API but not for the/repos/{owner}/{repo}/pulls/{number}/files
API.Extra updates:
NewGithubClient
: It was namedtransport
but it was not a Transport type. It's really an*http.Client
configured with the required GitHub credentials.ListOptions
andnextPage
logic. AllListFiles
calls now include the page number.