Can't create a keep-around reference if lock file exists
We see periodic incidents of this:
Failed to create locked file '/var/opt/gitlab/git-data/repositories/project/group/refs/keep-around/977e09540e868f3fec23fc795f507c4e5c0a66a9.lock': File exists
https://sentry.gitlap.com/gitlab/gitlabcom/issues/9791/
The ref was created successfully in that case, though.
This happened in NewNoteWorker
, but if it happened in PostReceive
or MergeWorker
this could halt everything.
In !5190 (merged), we catch Rugged::ReferenceError
, but this is Rugged::OSError
with a specific "File exists".
Digging into libgit2, I found that it does create a lock file while it's trying to create a ref. This is likely a sign another process is trying to create the same ref, so we should probably not fail here.
We can catch OSError, but we have to be careful we're not handling the right error.