Commit e6022d6d authored by Rémy Coutable's avatar Rémy Coutable Committed by Jose Ivan Vargas

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
parent 03b2c069
---
title: Fixes the 500 errors caused by a race condition in GPG's tmp directory handling
merge_request: 14194
author: Alexis Reigel
type: fixed
...@@ -69,11 +69,17 @@ module Gitlab ...@@ -69,11 +69,17 @@ module Gitlab
def optimistic_using_tmp_keychain def optimistic_using_tmp_keychain
previous_dir = current_home_dir previous_dir = current_home_dir
Dir.mktmpdir do |dir| tmp_dir = Dir.mktmpdir
GPGME::Engine.home_dir = dir GPGME::Engine.home_dir = tmp_dir
yield yield
end
ensure 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 GPGME::Engine.home_dir = previous_dir
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment