def ensure_connected(&block)
      unless (conn = stack(:connection)).empty?
        return yield(conn.first)
      end

      begin
        connection do |conn|
          connect(conn) unless conn.alive?
          conn.apply_credentials(@credentials)
          stack(:connection) << conn
          yield(conn)
        end
      rescue Exception => e
        if e.kind_of?(ConnectionPool::PoolShuttingDownError)
          @pool = nil
          Connection::Manager.delete_pool(self)
        end
        Failover.get(e).execute(e, self, &block)
      ensure
        end_execution(:connection)
      end
    end
def ensure_connected(&block)
      unless (conn = stack(:connection)).empty?
        return yield(conn.first)
      end

      begin
        connection do |conn|
          connect(conn) unless conn.alive?
          conn.apply_credentials(@credentials)
          stack(:connection) << conn
          yield(conn)
        end
      rescue Exception => e
        if e.kind_of?(ConnectionPool::PoolShuttingDownError)
          @pool = nil
          Connection::Manager.delete_pool(self)
        end
        Failover.get(e).execute(e, self, &block)
      ensure
        end_execution(:connection)
      end
    end
Yields the block if a connection can be established, retrying when a
 connection error is raised.

 @example Ensure we are connection.
   node.ensure_connected do
     #...
   end

 @raises [ ConnectionFailure ] When a connection cannot be established.

 @return [ nil ] nil.

 @since 1.0.0