-
-
Notifications
You must be signed in to change notification settings - Fork 6k
Adjustments to remove dangling repository locks #32485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
modules/git/repo_cleanup.go
Outdated
return nil | ||
} else { | ||
log.Trace("Checking if repository %s is locked [lock threshold is %s]", repoPath, threshold) | ||
return filepath.Walk(repoPath, func(filePath string, fileInfo os.FileInfo, err error) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think Walk is necessary since the lock files have a fixed relative path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lunny, Sadly I think we actually might :(
I've look at the source of gitlab referenced here and it appears that each refs can have its own lock (I've pasted the corresponding code snippet to make it easier for us to discuss)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is necessary (ask Copilot or some AI like: What kinds of "lock" files will git command generate in a repository when it is working?)
However, it shouldn't do so. If you do "Walk" for every git command, it slows down the whole system.
73cec03
to
51530a1
Compare
Signed-off-by: Bruno Sofiato <[email protected]>
I think we should first add a manual task to clean up these lock files. |
func hasGitProcessCrashed(err error) bool { | ||
if exitError, ok := err.(*exec.ExitError); ok { | ||
if runtime.GOOS == "windows" { | ||
log.Warn("Cannot realiably detected if the git process has crashed in windows. Assuming it hasn't [exitCode: %s, pid: %s]", exitError.ExitCode(), exitError.Pid()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this log useless warnings a lot on windows?
This PR allows Gitea to detect if a repo has any dangling locks (older than a threshold) and remove them if needed. It also detects if a git process has crashed (in that case, it will also remove any locks that remain).
By default, the threshold for a lock to be eligible for removal is
1 hour
. This can be changed via theDANGLING_LOCK_THRESHOLD
configuration parameter (the PR for the docs is still in the works).There are still some points that might need clarification.
refs
level so we must search for them by walking the repo's directory structure;Resolves #22578
P.S. It seems that the unit tests are breaking due to some timing issue (evidence attached)
P.S, Below is the description of the PR when it was a draft