mongodb/mongo-ruby-driver — pull request #454 by estolfo (2014-07-16 18:03:40+00:00)
Title: [Do not merge until Sam's test changes are in] Ruby 788 auth recursive lock

This fixes some messy code in our authentication module.

The issues and changes are:

1. Recursive locking caused by connection failure while authenticating a socket during pool#checkout.
The main problem was that within the pool#checkout method, we were getting a lock and were calling #check_auths, which applied authentication to a certain socket. If there was a connection failure while authenticating, you would eventually loop back around and try to grab the same pool lock in order to check that socket back into the pool.
Resolution: A method called #auth_command in the authentication module that creates an auth command message and catches its own errors, without involving the cursor. The cursor code is what would eventually lead you to loop back around and trying to grab the same lock you already have in the pool.

2. There were some deprecated methods that apply auth to all sockets in a pool that could also get you to a recursive locking situation. Resolution: Removal of code inside deprecated methods so that they are no-ops.

These issues came to our attention when Sam added the proper localhost exception handling into our test suite. I haven't written a specific test for this code because:

1. Is it manifested/tested in multiple places in Sam's auth test fixes branch anyway.

2. Any test I write now will break with Sam's auth test fixes.

I will therefore wait until after Sam's changes are in to write a specific test and to merge this code.