Fix: GPG tmp dir removal race condition

This commit is contained in:
Alexis Reigel 2017-09-13 11:31:37 +00:00 committed by Rémy Coutable
parent 4fb6848fdb
commit bb1cf2aaf9
2 changed files with 15 additions and 4 deletions

View File

@ -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

View File

@ -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