diff options
author | Stan Hu <stanhu@gmail.com> | 2016-07-26 13:15:48 +0000 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2016-07-26 13:15:48 +0000 |
commit | 8a95f1f32cd5d93044f4b7b4c9b606267910df79 (patch) | |
tree | 00dac39de251d7ef126d5708c3ca841f9944cd4a | |
parent | 9cf1bf64cf624c3914f9d9cd15beeae924e9ae94 (diff) | |
parent | 226c224234d8ac67f22fb162953e7ac905d42ad8 (diff) | |
download | gitlab-ce-8a95f1f32cd5d93044f4b7b4c9b606267910df79.tar.gz |
Merge branch '20156-rescue-reference-create-due-to-file-lock-exists' into 'master'
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.
```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
```
## Why was this MR needed?
## What are the relevant issue numbers?
Closes #20156
## Screenshots (if relevant)
## Does this MR meet the acceptance criteria?
- [x] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added
- ~~[ ] [Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md)~~
- ~~[ ] API support added~~
- Tests
- [ ] Added for this feature/bug
- [ ] All builds are passing
- [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides)
- [x] Branch has no merge conflicts with `master` (if you do - rebase it please)
- [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits)
See merge request !5497
-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 3d18f50f9d2..dca9b209582 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -19,6 +19,7 @@ v 8.11.0 (unreleased) v 8.10.2 (unreleased) - User can now search branches by name. !5144 - Fix backup restore. !5459 + - Rescue Rugged::OSError (lock exists) when creating references. !5497 - Disable MySQL foreign key checks before dropping all tables. !5472 - Use project ID in repository cache to prevent stale data from persisting across projects. !5460 - Ensure relative paths for video are rewritten as we do for images. !5474 diff --git a/app/models/repository.rb b/app/models/repository.rb index e9d5f4c91f8..d8775ecbd6c 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 |