fix(git): remove stale gpg lock files on startup (#40355)

keyboxd holds `public-keys.d/pubring.db.lock` for its whole lifetime,
and gpg only breaks a stale lock that names the current host and a dead
pid. After a container is re-created, signing, signed merges and auto
merge time out on the old container's lock, even after a graceful
shutdown.

At startup, Gitea now removes that lock from its default GnuPG home
without inspecting it, a running keyboxd keeps working without the file.
Admin-provided `GNUPGHOME` directories are left alone.

Fixes: https://github.com/go-gitea/gitea/issues/30781

Assisted-by: Claude Code:claude-opus-5-5

---------

Signed-off-by: silverwind <me@silverwind.io>
Co-authored-by: Mansur Akhmadi <10739460+mansur-akhmadi@users.noreply.github.com>
Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
authored and GitHub committed 2026-11-17 02:47:17 +00:00
1 parent 055105d42f
commit 09279b0763
1 file changed
+4
+4
View File
@@ -174,6 +174,10 @@ func InitFull() (err error) {
if err = InitSimple(); err != nil {
return err
}
// remove keyboxd's stale lock, gpg times out on it after a hostname change, like on container restarts
if gnupgHome := filepath.Join(gitcmd.HomeDir(), ".gnupg"); os.Getenv("GNUPGHOME") == gnupgHome {
_ = os.Remove(filepath.Join(gnupgHome, "public-keys.d", "pubring.db.lock"))
}
return syncGitConfig(context.Background())
}