Skip to content

Rescue Rugged::OSError (lock exists) when creating references.

What does this MR do?

Rescue an exception on concurrent scenarios. I was able to create a spec for this, because if you create the lock file before trying to create the reference the reference is created without a problem and the lock file is removed. So IMHO there is a race condition where more than one process is trying to create the same reference at the same time raising the exception, so I just added the patch without specs.

    it "attempting to call keep_around when exists a lock does not fail" do
      ref = repository.send(:keep_around_ref_name, sample_commit.id)
      path = File.join(repository.path, ref)
      lock_path = "#{path}.lock"

      FileUtils.mkdir_p(path)
      File.open(lock_path, 'w') { |f| f.write('') }

      begin
        # No exception is raised because the lock file is removed at some point in the process
        repository.keep_around(sample_commit.id)
      ensure
        File.delete(path)
        File.delete(lock_path)
      end
    end

Why was this MR needed?

What are the relevant issue numbers?

Closes #20156 (closed)

Screenshots (if relevant)

Does this MR meet the acceptance criteria?

Merge request reports