Git GPG Error: database_open Waiting for Lock
Problem Statement
When attempting Git operations that require GPG signing (such as commits), you may encounter a blocking error where GPG appears stuck indefinitely. The error typically shows:
gpg: Note: database_open 134217901 waiting for lock (held by 9857) ...
[GNUPG:] FAILURE sign 134250628
gpg: signing failed: Operation timed out
Or repeatedly displays:
--list-keys
gpg: Note: database_open 134217901 waiting for lock (held by 9857) ...
gpg: Note: database_open 134217901 waiting for lock (held by 9857) ...
Key Symptoms
- Git operations hang during signing verification
- GPG reports waiting for a lock held by a process ID (PID)
- Commit/push operations fail after timeout periods
- Issue persists after token resets, repository clones, or credential updates
- Commonly observed in RStudio and terminal Git operations
Solution: Remove GPG Lock File
The core issue is a conflicting lock file in GPG's directory. This commonly occurs when a previous GPG process crashed or failed to release resources properly.
Default GPG Path
Solutions assume GPG's home directory is at ~/.gnupg
. If you have a custom GNUPGHOME
environment variable, adjust paths accordingly.
Step-by-Step Fix
Terminate existing GPG processes:
bashgpgconf --kill all
Remove the lock file causing the conflict:
bashrm -f ~/.gnupg/S.gpg-agent
Verify resolution by listing GPG keys:
bashgpg --list-keys
Successful execution confirms the lock is released.
Alternate Approach for Persistent Locks
If the error persists, remove all GPG lock files (use cautiously):
rm -f ~/.gnupg/*.lock
Workaround: Temporarily Disable GPG Signing
If your workflow doesn't require signed commits, temporarily disable signing to bypass the issue.
Disable per Repository
# Disable signing for current repo
git config commit.gpgsign false
Disable Globally
# Disable signing for all repositories
git config --global commit.gpgsign false
WARNING
This bypasses security verification. Re-enable signing once the lock issue is resolved:
git config commit.gpgsign true
Why This Works
Root Cause Analysis
- GPG uses lock files to prevent concurrent access to sensitive operations
- When a Git signing process crashes (e.g., due to timeout or system interrupt), it leaves a stale lock
- Subsequent operations hang indefinitely waiting for the orphaned lock
Solution Benefits Over Disabling Signing
- Maintains commit verification integrity
- Addresses the underlying file system conflict
- Prevents recurrence in future signing operations
- Doesn't compromise security workflows
Additional Troubleshooting
If issues persist:
- Identify locking process:bash
ps aux | grep 9857 # Replace 9857 with PID from error
- Kill the process if it's orphaned:bash
kill -9 9857
- Refresh GPG connections:bash
gpg-connect-agent reloadagent /bye
Reference Solution: Git Commit Freeze Fix