def send_request(request)
      api_name = Protocol.api_name(request.api_key)

      # Default notification payload.
      notification = {
        broker_host: @host,
        api: api_name,
        request_size: 0,
        response_size: 0,
      }

      raise IdleConnection if idle?

      @logger.push_tags(api_name)
      @instrumenter.instrument("request.connection", notification) do
        open unless open?

        @correlation_id += 1

        @logger.debug "Sending #{api_name} API request #{@correlation_id} to #{to_s}"

        write_request(request, notification)

        response_class = request.response_class
        response = wait_for_response(response_class, notification) unless response_class.nil?

        @last_request = Time.now

        response
      end
    rescue SystemCallError, EOFError, IOError => e
      close

      raise ConnectionError, "Connection error #{e.class}: #{e}"
    ensure
      @logger.pop_tags
    end
def send_request(request)
      api_name = Protocol.api_name(request.api_key)

      # Default notification payload.
      notification = {
        broker_host: @host,
        api: api_name,
        request_size: 0,
        response_size: 0,
      }

      raise IdleConnection if idle?

      @logger.push_tags(api_name)
      @instrumenter.instrument("request.connection", notification) do
        open unless open?

        @correlation_id += 1

        @logger.debug "Sending #{api_name} API request #{@correlation_id} to #{to_s}"

        write_request(request, notification)

        response_class = request.response_class
        response = wait_for_response(response_class, notification) unless response_class.nil?

        @last_request = Time.now

        response
      end
    rescue SystemCallError, EOFError, IOError => e
      close

      raise ConnectionError, "Connection error #{e.class}: #{e}"
    ensure
      @logger.pop_tags
    end
Sends a request over the connection.

 @param request [#encode, #response_class] the request that should be
   encoded and written.

 @return [Object] the response.