mirror of
https://github.com/go-gitea/gitea.git
synced 2026-12-04 15:54:57 +00:00
fix(mirror): skip duplicate pull mirror syncs instead of blocking workers (#40550)
Switch `SyncPullMirror` to `globallock.TryLock` (matching `services/cron/tasks.go`) so duplicate requests return immediately when a sync for that repository is already in progress. Fixes: https://github.com/go-gitea/gitea/issues/40549 --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
1 parent
024af0ebca
commit
943eb1073d
2 files changed
+9
-7
No files matched your search
@@ -260,5 +260,5 @@ func PanicInDevOrTesting(msg string, a ...any) {
|
||||
if !IsProd || IsInTesting {
|
||||
panic(fmt.Sprintf(msg, a...))
|
||||
}
|
||||
log.ErrorWithSkip(1, msg, a...)
|
||||
log.ErrorWithSkip(1, msg+", stack:\n%s", append(a, log.Stack(2))...)
|
||||
}
|
||||
@@ -283,19 +283,21 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool {
|
||||
log.Trace("SyncMirrors [repo_id: %v]", repoID)
|
||||
defer func() {
|
||||
err := recover()
|
||||
if err == nil {
|
||||
return
|
||||
if err != nil {
|
||||
setting.PanicInDevOrTesting("PANIC when SyncMirrors[repo_id: %d]: %v", repoID, err)
|
||||
}
|
||||
// There was a panic whilst syncMirrors...
|
||||
log.Error("PANIC whilst SyncMirrors[repo_id: %d] Panic: %v\nStacktrace: %s", repoID, err, log.Stack(2))
|
||||
}()
|
||||
|
||||
releaser, err := globallock.Lock(ctx, getRepoPullMirrorLockKey(repoID))
|
||||
locked, releaser, err := globallock.TryLock(ctx, getRepoPullMirrorLockKey(repoID))
|
||||
if err != nil {
|
||||
log.Error("globallock.Lock(): %v", err)
|
||||
log.Error("globallock.TryLock(): %v", err)
|
||||
return false
|
||||
}
|
||||
defer releaser()
|
||||
if !locked {
|
||||
log.Trace("SyncMirrors [repo_id: %v]: already syncing, skipping", repoID)
|
||||
return false
|
||||
}
|
||||
|
||||
m, err := repo_model.GetMirrorByRepoID(ctx, repoID)
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user