MergeWorker merged from the wrong SHA of a branch
ZenDesk: https://gitlab.zendesk.com/agent/tickets/31125
This diagram sums up the issue:
What happened?
MR 3482 and 3840 were merged properly. Then MR 3501 got merged, but it used the old head of the branch (9981f) instead of the latest (020c08). This resulted in losing commits in between (a5189 and 02c08).
Note that these MRs did not get merged in quick succession. They were hours apart.
Looking at MergeService
, we see:
commit_id = repository.merge(current_user, merge_request.source_sha, merge_request.target_branch, options)
source_sha
is the SHA of the last commit in the MR.
target_branch
is the target branch name (e.g. refs/heads/master
).
Repository#merge
does this:
def merge(user, source_sha, target_branch, options = {})
our_commit = rugged.branches[target_branch].target
their_commit = rugged.lookup(source_sha)
Here it looks up the commit of the target branch. If this is stale for some reason, we may see an issue.
How does this get stale? Possible reasons:
- NFS cache
- Rugged/libgit2 apparently has an in-memory cache; I wonder if this is a cause.