Skip to content

receive-pack: always unlink `.keep` files when exiting early

Patrick Steinhardt requested to merge pks-receive-pack-unlink-lockfile-atexit into main

When accepting a packfile in git-receive-pack(1), we feed that packfile into git-index-pack(1) to generate the packfile index. As the packfile would often only contain unreachable objects until the references have been updated, concurrently running garbage collection might be tempted to delete the packfile right away and thus cause corruption. To fix this, we ask git-index-pack(1) to create a .keep file before moving the packfile into place, which is getting deleted again once all of the reference updates have been processed.

Now in production systems we have observed that those .keep files are sometimes not getting deleted as expected, where the result is that repositories tend to grow packfiles that are never deleted over time. This seems to be caused by a race when git-receive-pack(1) is killed after we have migrated the kept packfile from the quarantine directory into the main object database. While this race window is typically small it can be extended for example by installing a proc-receive hook.

Fix this race by installing an atexit(3P) handler that unlinks the keep file.

Closes #148 (closed).

Edited by Patrick Steinhardt

Merge request reports