Race condition in DeleteMergedBranchesService
branches = project.repository.merged_branch_names
# Prevent deletion of branches relevant to open merge requests
branches -= merge_request_branch_names
# Prevent deletion of protected branches
branches = branches.reject { |branch| ProtectedBranch.protected?(project, branch) }
branches.each do |branch|
DeleteBranchService.new(project, current_user).execute(branch)
end
The branches deletion takes quite some time as Gitaly will execute the required hooks. So the following flow could happen
- User creates a branch for an issue, up to date with master (but does not open a merge request)
- Master gets ahead of the new branch by at least 1 commit
- User "Deletes merged branches"
- DeleteMergedBranches detects that branch to be merged, as the commit of the branch is in master
- User pushes a new commit to the new branch
- DeleteMergedBranches deletes the branch as it was merged 10 seconds ago
/cc @DouweM
Edited by Michelle Gill