summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2017-09-13 11:31:37 +0000
committerJose Ivan Vargas <jvargas@gitlab.com>2017-09-15 23:05:17 -0500
commite6022d6ddd336c428d063c220c00800734e352b9 (patch)
tree51c080d70e2fd362446f72de183ae2dee2d7e967
parent03b2c069e56d2957c9d49bd837cecab11f3f96d7 (diff)
downloadgitlab-ce-e6022d6ddd336c428d063c220c00800734e352b9.tar.gz
Merge branch 'fix/gpg-tmp-dir-removal-race-condition' into 'master'
Fix: GPG tmp dir removal race condition Ignore any errors when removing the tmp directory, as we may run into a race condition: The `gpg-agent` agent process may clean up some files as well while `FileUtils.remove_entry` is iterating the directory and removing all its contained files and directories recursively, which could raise an error. Closes #36998 See merge request !14194
-rw-r--r--changelogs/unreleased/fix-gpg-tmp-dir-removal-race-condition.yml5
-rw-r--r--lib/gitlab/gpg.rb14
2 files changed, 15 insertions, 4 deletions
diff --git a/changelogs/unreleased/fix-gpg-tmp-dir-removal-race-condition.yml b/changelogs/unreleased/fix-gpg-tmp-dir-removal-race-condition.yml
new file mode 100644
index 00000000000..e75f188913f
--- /dev/null
+++ b/changelogs/unreleased/fix-gpg-tmp-dir-removal-race-condition.yml
@@ -0,0 +1,5 @@
+---
+title: Fixes the 500 errors caused by a race condition in GPG's tmp directory handling
+merge_request: 14194
+author: Alexis Reigel
+type: fixed
diff --git a/lib/gitlab/gpg.rb b/lib/gitlab/gpg.rb
index 025f826e65f..0d5039ddf5f 100644
--- a/lib/gitlab/gpg.rb
+++ b/lib/gitlab/gpg.rb
@@ -69,11 +69,17 @@ module Gitlab
def optimistic_using_tmp_keychain
previous_dir = current_home_dir
- Dir.mktmpdir do |dir|
- GPGME::Engine.home_dir = dir
- yield
- end
+ tmp_dir = Dir.mktmpdir
+ GPGME::Engine.home_dir = tmp_dir
+ yield
ensure
+ # Ignore any errors when removing the tmp directory, as we may run into a
+ # race condition:
+ # The `gpg-agent` agent process may clean up some files as well while
+ # `FileUtils.remove_entry` is iterating the directory and removing all
+ # its contained files and directories recursively, which could raise an
+ # error.
+ FileUtils.remove_entry(tmp_dir, true)
GPGME::Engine.home_dir = previous_dir
end
end