forgejo/services
Royce Remer adc2a215c1
Fail mirroring more gracefully (#34002)
* 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

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.

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
(cherry picked from commit e0ad72e2233f885669c26d9063a91abd594fb9f6)
2025-04-01 02:28:02 +02:00
..
actions Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
agit chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
asymkey chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
attachment Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
auth Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
automerge chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
context Git client will follow 301 but 307 (#34005) 2025-04-01 02:28:02 +02:00
contexttest Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
convert Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
cron chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
doctor feat: use XORM EngineGroup instead of single Engine connection (#7212) 2025-03-30 11:34:02 +00:00
externalaccount chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
f3 Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
federation chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
feed chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
forgejo chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
forms fix: validate input for default_{merge,update}_style (#7395) 2025-03-31 03:33:18 +00:00
gitdiff Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
indexer chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
issue Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
lfs Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
mailer Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
markup chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
migrations Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
mirror Fail mirroring more gracefully (#34002) 2025-04-01 02:28:02 +02:00
notify chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
org chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
packages Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
pull Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
release Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
remote chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
repository Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
secrets chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
shared/automerge chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
task chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
uinotification chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
user Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
webhook Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
wiki Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00