mongodb/mongo-ruby-driver — pull request #149 by nelhage (2013-01-17 02:29:11+00:00)
Title: Mongo::Pool: Always try at least once to get a socket.

This is a bit of a screw case, but we have occasionally seen spurious ConnectionTimeoutError's on single-threaded programs that I suspect are attributable to this. I suspect that the specific case is if you happen to trigger a GC in between entering the function and checking the timeout, and the machine is hosed enough (e.g. swapping heavily)

Obviously, ideally machines would never get this loaded, but I think it's preferable that we don't cause spurious timeouts if it does -- this patch gives us the guarantee that if there is an available socket, a single-threaded program will always successfully check one out, which feels like desirable semantics -- basically, it means that single-threaded programs always behave as though there were just a single socket, with no pooling.

---

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.