Completes the request by calling the state method.

    Args:
      method_name: The name of the state method to call.
      request: A RequestState protobuf.
      responses: A list of GrrMessages responding to the request.

def RunStateMethod(self, method_name, request=None, responses=None):
    """Completes the request by calling the state method.

    Args:
      method_name: The name of the state method to call.
      request: A RequestState protobuf.
      responses: A list of GrrMessages responding to the request.
    """
    if self._TerminationPending():
      return

    client_id = None
    try:
      self.context.current_state = method_name
      if request and responses:
        client_id = request.client_id or self.runner_args.client_id
        logging.debug("%s Running %s with %d responses from %s",
                      self.session_id, method_name, len(responses), client_id)

      else:
        logging.debug("%s Running state method %s", self.session_id,
                      method_name)

      # Extend our lease if needed.
      self.flow_obj.HeartBeat()
      try:
        method = getattr(self.flow_obj, method_name)
      except AttributeError:
        raise FlowRunnerError("Flow %s has no state method %s" %
                              (self.flow_obj.__class__.__name__, method_name))

      # Prepare a responses object for the state method to use:
      responses = flow_responses.Responses.FromLegacyResponses(
          request=request, responses=responses)

      self.SaveResourceUsage(responses.status)

      stats_collector_instance.Get().IncrementCounter("grr_worker_states_run")

      if method_name == "Start":
        stats_collector_instance.Get().IncrementCounter(
            "flow_starts", fields=[self.flow_obj.Name()])
        method()
      else:
        method(responses)

      if self.sent_replies:
        self.ProcessRepliesWithOutputPlugins(self.sent_replies)
        self.sent_replies = []

    # We don't know here what exceptions can be thrown in the flow but we have
    # to continue. Thus, we catch everything.
    except Exception as e:  # pylint: disable=broad-except
      # This flow will terminate now

      # TODO(user): Deprecate in favor of 'flow_errors'.
      stats_collector_instance.Get().IncrementCounter("grr_flow_errors")

      stats_collector_instance.Get().IncrementCounter(
          "flow_errors", fields=[self.flow_obj.Name()])
      logging.exception("Flow %s raised %s.", self.session_id, e)

      self.Error(traceback.format_exc(), client_id=client_id)