From c19032f7f4a75fac5f1dab51b2b12ed4f4884881 Mon Sep 17 00:00:00 2001 From: mintaka Date: Sun, 22 Nov 2026 00:05:59 -0500 Subject: [PATCH] fix(woodpecker): log SetPerm permission refresh duration (RIG-11816) ## What does this do Ports RigelBuild/woodpecker#188 into the fork. `SetPerm` now logs each forge permission refresh with its duration, the age of the stored permission, the repo, the user, and the error. A refresh over 5 s also logs a WARN line. ## Why do we need it RIG-11816 reports `/config` requests stalling 31 to 100 s. One suspect is the `_forge.Repo` call in `SetPerm`. It has no timeout, and it runs when the stored permission is over an hour old. These logs show the duration after deploy, so the suspect can be confirmed or ruled out. ## Summary - `forks/woodpecker/server/router/middleware/session/repo.go`: timing and two log lines around `_forge.Repo`. No control-flow, timeout, or error-handling change. ## Verification - `gofmt -l` clean on the touched file. - Test run off-box on macpro2013 (`go test -tags test`), see the PR body. ## Risks One INFO line per stale-permission refresh, at most one per user and repo per hour. Ports RigelBuild/woodpecker#188. ## Spec impact Spec-impact: none Refs RIG-11816 Co-authored-by: Matt Wilkinson --- .../server/router/middleware/session/repo.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/forks/woodpecker/server/router/middleware/session/repo.go b/forks/woodpecker/server/router/middleware/session/repo.go index e5f289f21..48cdf00c2 100644 --- a/forks/woodpecker/server/router/middleware/session/repo.go +++ b/forks/woodpecker/server/router/middleware/session/repo.go @@ -125,7 +125,26 @@ func SetPerm() gin.HandlerFunc { // a user of another forge has no permissions on this repo and // their token must not be sent to the repo's forge if user.ForgeID == repo.ForgeID && time.Unix(perm.Synced, 0).Add(time.Hour).Before(time.Now()) { + syncedAge := time.Since(time.Unix(perm.Synced, 0)) + start := time.Now() _repo, err := _forge.Repo(c, user, repo.ForgeRemoteID, repo.Owner, repo.Name) + duration := time.Since(start) + log.Info(). + Dur("duration", duration). + Dur("synced_age", syncedAge). + Str("repo", repo.FullName). + Str("user", user.Login). + Err(err). + Msg("SetPerm refresh") + if duration > 5*time.Second { + log.Warn(). + Dur("duration", duration). + Dur("synced_age", syncedAge). + Str("repo", repo.FullName). + Str("user", user.Login). + Err(err). + Msg("SetPerm refresh slow") + } if err == nil { log.Debug().Msgf("synced user permission for %s %s", user.Login, repo.FullName) _repo.ForgeID = repo.ForgeID