Skip to content

housekeeping: Clean packfile locks left behind by fetches and pushes

When writing packfiles into the repository, both git-receive-pack(1) and git-fetch-pack(1) will first create a .keep file to keep the packfiles alive while the references have not yet been updated to point to the new objects. This is done in order to keep the packfiles alive so that no concurrent garbage collection will prune them.

There is a race in Git though that may cause the lock to not be deleted when the commands receive a signal at the wrong point in time. This has caused us to accumulate these packfile locks in some repositories as we sometimes lose the race. And as Git knows to never touch a packfile that has such a lock, the objects will be kept alive indefinitely.

Implement new cleanup logic to prune stale packfile locks after a grace period. Luckily, Git will write a message into the .keep files that allows us to easily identify them as being written by either of the mentioned commands. This allows us to delete only these specific locks while keeping around any other locks that may have been written by an administrator in order to keep objects alive, whatever the reason.

Closes #4768 (closed).

Merge request reports