Permalink
Browse files

Mongo::Pool: Always try at least once to get a socket.

On heavily-loaded machines with a small timeout, it is actually
possible for the timeout to expire before even a single pass through
the checkout loop. This results in throwing ConnectionTimeoutError's,
even though nothing directly mongo-related is actually timing out or
going wrong.

Always pass through the loop at least once before timing out, so that
we are guaranteed to find a socket if there is one immediately
available.
  • Loading branch information...
1 parent 0c6243f commit 0363dc4163677bece87f18090d41df0ead53a7e3 @nelhage committed Dec 10, 2012
Showing with 6 additions and 6 deletions.
  1. +6 −6 lib/mongo/util/pool.rb
View
@@ -270,12 +270,6 @@ def checkout
@client.connect if !@client.connected?
start_time = Time.now
loop do
- if (Time.now - start_time) > @timeout
- raise ConnectionTimeoutError, "could not obtain connection within " +
- "#{@timeout} seconds. The max pool size is currently #{@size}; " +
- "consider increasing the pool size or timeout."
- end
-
@connection_mutex.synchronize do
check_prune
socket = nil
@@ -312,6 +306,12 @@ def checkout
@queue.wait(@connection_mutex)
end
end
+
+ if (Time.now - start_time) > @timeout
+ raise ConnectionTimeoutError, "could not obtain connection within " +
+ "#{@timeout} seconds. The max pool size is currently #{@size}; " +
+ "consider increasing the pool size or timeout."
+ end
end
end

0 comments on commit 0363dc4

Please sign in to comment.