diff options
author | Robert Speicher <rspeicher@gmail.com> | 2017-07-11 20:38:27 +0300 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2017-07-11 23:49:57 +0300 |
commit | b904a7dbd208f069f618e5ea60de56d8687c606c (patch) | |
tree | 46bfc84ec564c9b9e0149728456bd0f8e9870347 /lib/gitlab/redis | |
parent | 2a5d2ecfbfa4494b1b58e869a9d8988af2f8a2b4 (diff) |
Make `Redis::Wrapper#_raw_config` and `#fetch_config` more resilient
These two methods now handle two additional real-world possibilities:
1. `config/resque.yml` not being present
2. `config/resque.yml` being present but not containing YAML
Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/34941
Diffstat (limited to 'lib/gitlab/redis')
-rw-r--r-- | lib/gitlab/redis/wrapper.rb | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/lib/gitlab/redis/wrapper.rb b/lib/gitlab/redis/wrapper.rb index 10c16a962ca..c43b37dde74 100644 --- a/lib/gitlab/redis/wrapper.rb +++ b/lib/gitlab/redis/wrapper.rb @@ -33,13 +33,16 @@ module Gitlab def _raw_config return @_raw_config if defined?(@_raw_config) - begin - @_raw_config = ERB.new(File.read(config_file_name)).result.freeze - rescue Errno::ENOENT - @_raw_config = false - end - - @_raw_config + @_raw_config = + begin + if filename = config_file_name + ERB.new(File.read(filename)).result.freeze + else + false + end + rescue Errno::ENOENT + false + end end def default_url @@ -116,7 +119,16 @@ module Gitlab end def fetch_config - self.class._raw_config ? YAML.load(self.class._raw_config)[@rails_env] : false + return false unless self.class._raw_config + + yaml = YAML.load(self.class._raw_config) + + # If the file has content but it's invalid YAML, `load` returns false + if yaml + yaml.fetch(@rails_env, false) + else + false + end end end end |