-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Fail mirroring more gracefully: #34002
base: main
Are you sure you want to change the base?
Conversation
39f376f
to
c6337ab
Compare
services/mirror/mirror_pull.go
Outdated
case strings.Contains(stderrMessage, "unable to resolve reference") && strings.Contains(stderrMessage, "reference broken"): | ||
case strings.Contains(stderrMessage, "remote error") && strings.Contains(stderrMessage, "not our ref"): | ||
case strings.Contains(stderrMessage, "cannot lock ref") && strings.Contains(stderrMessage, "but expected"): | ||
case strings.Contains(stderrMessage, "Unable to create") && strings.Contains(stderrMessage, ".lock"): | ||
default: | ||
return true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't seem right. Golang switch
doesn't "fallthrough" by default.
It's better to create a test for this function, and add comments for each case: why it would happen and why it could be ignored.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the feedback, I documented the existing logic in a test, along with the new cases of it I've found helpful at my company.
c6337ab
to
62a85f3
Compare
* reuse recoverable error checks across mirror_pull * add new cases for 'cannot lock ref/not our ref' (race condition in fetch) and 'Unable to create/lock" * move lfs sync right after commit graph write, and before other maintenance which may fail * try a prune for 'broken reference' as well as 'not our ref' * always sync LFS right after commit graph write, and before other maintenance which may fail
62a85f3
to
1871276
Compare
This handles a few cases where our very large and very active repositories could serve mirrored git refs, but be missing lfs files:
Case 1 (multiple variants): Race condition in git fetch
There was already a check for 'unable to resolve reference' on a failed git fetch, after which a git prune and then subsequent fetch are performed. This is to work around a race condition where the git remote tells Gitea about a ref for some HEAD of a branch, then fails a few seconds later because the remote branch was deleted, or the ref was updated (force push).
There are two more variants to the error message you can get, but for the same kind of race condition. These may be related to the git binary version Gitea has access to (in my case, it was 2.48.1).
Case 2: githttp.go can serve updated git refs before it's synced lfs oids
There is probably a more aggressive refactor we could do here to have the cat-file loop use FETCH_HEAD instead of relying on the commit graphs to be committed locally (and thus serveable to clients of Gitea), but a simple reduction in the occurrences of this for me was to move the lfs sync block immediately after the commit-graph write and before any other time-consuming (or potentially erroring/exiting) blocks.