Skip to content

Commit

Permalink
Use thread local variables for pool pinning rather than lookup tables…
Browse files Browse the repository at this point in the history
… to prevent leaked Thread references
  • Loading branch information
cheald committed Dec 21, 2012
1 parent 01b163b commit 6298e2a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/mongo/mongo_replica_set_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,11 @@ def ensure_manager
end

def pin_pool(pool)
@manager.pinned_pools[Thread.current] = pool if @manager
Thread.current[:"mongo_pinned_pool_#{@manager.object_id}"] = pool if @manager
end

def unpin_pool(pool)
@manager.pinned_pools[Thread.current] = nil if @manager
Thread.current[:"mongo_pinned_pool_#{@manager.object_id}"] = nil if @manager
end

def get_socket_from_pool(pool)
Expand Down
6 changes: 1 addition & 5 deletions lib/mongo/util/pool_manager.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ class PoolManager
:secondary_pool, :secondary_pools, :hosts, :nodes, :members, :seeds,
:max_bson_size

attr_accessor :pinned_pools

# Create a new set of connection pools.
#
# The pool manager will by default use the original seed list passed
Expand All @@ -16,7 +14,6 @@ class PoolManager
# time. The union of these lists will be used when attempting to connect,
# with the newly-discovered nodes being used first.
def initialize(client, seeds=[])
@pinned_pools = {}
@client = client
@seeds = seeds
@previously_connected = false
Expand Down Expand Up @@ -104,7 +101,7 @@ def read_pool(mode=@client.read,
tags=@client.tag_sets,
acceptable_latency=@client.acceptable_latency)

pinned = pinned_pools[Thread.current]
pinned = Thread.current[:"mongo_pinned_pool_#{self.object_id}"]

if pinned && pinned.matches_mode(mode) && pinned.matches_tag_sets(tags) && pinned.up?
pool = pinned
Expand Down Expand Up @@ -158,7 +155,6 @@ def initialize_data
@hosts = Set.new
@members = Set.new
@refresh_required = false
@pinned_pools = {}
end

# Connect to each member of the replica set
Expand Down

0 comments on commit 6298e2a

Please sign in to comment.