diff options
author | Stan Hu <stanhu@gmail.com> | 2016-07-26 13:15:48 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-07-27 13:23:56 +0200 |
commit | 5dc2cadf3aa8fbbba09c2b914dd9c647b9b49ff0 (patch) | |
tree | dd4e6ddd3d4259c42eae494554ca893db6c1feb6 | |
parent | 53c7a1fd2b5b6f8f817858b7648f90c46121b4ed (diff) | |
download | gitlab-ce-5dc2cadf3aa8fbbba09c2b914dd9c647b9b49ff0.tar.gz |
Merge branch '20156-rescue-reference-create-due-to-file-lock-exists' into 'master'
Rescue Rugged::OSError (lock exists) when creating references.
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.
```ruby
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
```
See merge request !5497
Signed-off-by: Rémy Coutable <remy@rymai.me>
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | app/models/repository.rb | 3 |
2 files changed, 4 insertions, 0 deletions
diff --git a/CHANGELOG b/CHANGELOG index cbceabbda56..88ae55a19c6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -14,6 +14,7 @@ v 8.10.2 (unreleased) - Add ENV variable to skip repository storages validations. !5478 - Added `*.js.es6 gitlab-language=javascript` to `.gitattributes`. !5486 - Don't show comment button in gutter of diffs on MR discussion tab. !5493 + - Rescue Rugged::OSError (lock exists) when creating references. !5497 v 8.10.1 - Refactor repository storages documentation. !5428 diff --git a/app/models/repository.rb b/app/models/repository.rb index 791a1c1b63e..830b9dea485 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -211,6 +211,9 @@ class Repository rugged.references.create(keep_around_ref_name(sha), sha, force: true) rescue Rugged::ReferenceError => ex Rails.logger.error "Unable to create keep-around reference for repository #{path}: #{ex}" + rescue Rugged::OSError => ex + raise unless ex.message =~ /Failed to create locked file/ && ex.message =~ /File exists/ + Rails.logger.error "Unable to create keep-around reference for repository #{path}: #{ex}" end end |