Skip to content

Commit

Permalink
client should return a Tankard::Client object in all instances now.
Browse files Browse the repository at this point in the history
In the previous version if another thread set @client to nil after the cas but before the value is retrieved client would return nil.
The loop is unbounded so under heavy contention the loop might run for a while.  To currently get into that case you would need to keep reconfiguring tankard.
  • Loading branch information
matthewshafer committed Dec 30, 2014
1 parent 6e6f679 commit 3297fd4
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/tankard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@
#
# @author Matthew Shafer
module Tankard
@client = ::Atomic.new
@client = ::Atomic.new(nil)

class << self
include Configuration

def client
@client.compare_and_swap(nil, Tankard::Client.new(credentials))
@client.value
tankard_client = nil

loop do
tankard_client = @client.value
break if tankard_client
@client.compare_and_swap(nil, Tankard::Client.new(credentials))
end

tankard_client
end

def respond_to?(method)
Expand Down

0 comments on commit 3297fd4

Please sign in to comment.