diff options
| author | Yorick Peterse <yorickpeterse@gmail.com> | 2016-09-30 12:32:18 +0000 |
|---|---|---|
| committer | Yorick Peterse <yorickpeterse@gmail.com> | 2016-09-30 12:32:18 +0000 |
| commit | b9daced7a2814fa74a3f0dddf38858100678c6b1 (patch) | |
| tree | 4120bf0d5d747f731aa52f5dbf4264ccdbcd7ffb /lib | |
| parent | d0ef55624c017e1bf28af42f457af0aeec26967c (diff) | |
| parent | 52ee85e7bf35d372285d70cc93016854774839b1 (diff) | |
| download | gitlab-ce-b9daced7a2814fa74a3f0dddf38858100678c6b1.tar.gz | |
Merge branch 'initialize-redis' into 'master'
Initialize Redis pool in single-threaded context
See merge request !6613
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/gitlab/redis.rb | 24 |
1 files changed, 6 insertions, 18 deletions
diff --git a/lib/gitlab/redis.rb b/lib/gitlab/redis.rb index 69c4ef721d5..3faab937726 100644 --- a/lib/gitlab/redis.rb +++ b/lib/gitlab/redis.rb @@ -11,13 +11,6 @@ module Gitlab DEFAULT_REDIS_URL = 'redis://localhost:6379' CONFIG_FILE = File.expand_path('../../config/resque.yml', __dir__) - # To be thread-safe we must be careful when writing the class instance - # variables @_raw_config and @pool. Because @pool depends on @_raw_config we need two - # mutexes to prevent deadlock. - RAW_CONFIG_MUTEX = Mutex.new - POOL_MUTEX = Mutex.new - private_constant :RAW_CONFIG_MUTEX, :POOL_MUTEX - class << self # Do NOT cache in an instance variable. Result may be mutated by caller. def params @@ -31,24 +24,19 @@ module Gitlab end def with - if @pool.nil? - POOL_MUTEX.synchronize do - @pool = ConnectionPool.new { ::Redis.new(params) } - end - end + @pool ||= ConnectionPool.new { ::Redis.new(params) } @pool.with { |redis| yield redis } end def _raw_config return @_raw_config if defined?(@_raw_config) - RAW_CONFIG_MUTEX.synchronize do - begin - @_raw_config = File.read(CONFIG_FILE).freeze - rescue Errno::ENOENT - @_raw_config = false - end + begin + @_raw_config = File.read(CONFIG_FILE).freeze + rescue Errno::ENOENT + @_raw_config = false end + @_raw_config end end |
