def rescue_connection_failure(max_retries = 40)
      success = false
      retries = 0
      while !success
        begin
          yield
          success = true
        rescue mongo_error_type => e
          raise e if (retries += 1) >= max_retries
          sleep 0.25
        end
      end
    end
def rescue_connection_failure(max_retries = 40)
      success = false
      retries = 0
      while !success
        begin
          yield
          success = true
        rescue mongo_error_type => e
          raise e if (retries += 1) >= max_retries
          sleep 0.25
        end
      end
    end
Use retry alg from mongodb to gobble up connection failures during replica set master vote
 Defaults to a 10 second wait