diff options
author | Stan Hu <stanhu@gmail.com> | 2016-07-22 06:38:02 -0700 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2016-07-22 06:38:02 -0700 |
commit | 391064830d82c4b009ab7f698cba38141f449f76 (patch) | |
tree | c7db53a78bde06854d00bd25f0e83f2886b00bdf /app/models/repository.rb | |
parent | 12dd0f62012c6df8bd67abc2d9c5c54bd82366f7 (diff) | |
download | gitlab-ce-391064830d82c4b009ab7f698cba38141f449f76.tar.gz |
Gracefully handle case when keep-around references are corrupted or exist alreadyhandle-invalid-kept-around-references
We were seeing a number of error messages when attempting to create a keep-around ref:
1. Failed to create locked file `refs/keep-around/XYZ`: File exists
2. Failed to write reference `refs/keep-around/XYZ`: a reference with that name already exists.
I'm not sure how these happen, but I suspect when multiple workers attempt to write the same
file we may have an issue. The force parameter should help ensure the file gets created,
as well as the rescues to prevent 500 Errors.
Rugged/libgit2 unfortunately do not allow you to delete or re-create a reference that has
been corrupted, even with the force parameter.
Closes #20109
Diffstat (limited to 'app/models/repository.rb')
-rw-r--r-- | app/models/repository.rb | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb index 46a04eb80cd..1d3df6f9eaf 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -211,11 +211,20 @@ class Repository return if kept_around?(sha) - rugged.references.create(keep_around_ref_name(sha), sha) + # This will still fail if the file is corrupted (e.g. 0 bytes) + begin + 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}" + end end def kept_around?(sha) - ref_exists?(keep_around_ref_name(sha)) + begin + ref_exists?(keep_around_ref_name(sha)) + rescue Rugged::ReferenceError + false + end end def tag_names |