http request count is zero

Dk Jack dnj0496 at gmail.com
Tue Aug 10 22:35:24 UTC 2021


Hi,
I am seeing an alert in the nginx error.log with the message "http request
count is zero". It seems to be from this code in
src/http/ngx_http_request.c:

if (r->count == 0) {
  ngx_log_error(NGX_LOG_ALERT, c->log, 0, "http request count is zero");
}

These alerts are showing up for requests that receive a NGX_HTTP_FORBIDDEN
from my module. What does it mean when "r->count" is zero? Is there some
additional stuff I must do in my module to avoid seeing this message? Any
help in understanding the issue is appreciated. I've included  my code for
sending the response. Thanks.

Regards,
Dk.


ngx_buf_t *buf = ngx_create_temp_buf(r->pool, buf_size);
...
ngx_int_t
send_response(ngx_http_request_t *r, ngx_uint_t http_status, ngx_buf_t *buf)
{
  ngx_int_t rc;
  ngx_log_t *log = r->connection->log;

  if (NULL == buf) {
    ngx_log_error(NGX_LOG_ERR, log, 0, "%s: Invalid input buffer",
__FUNCTION__);
    return NGX_ERROR;
  }

  rc = ngx_http_discard_request_body(r);
  if (rc != NGX_OK) {
    ngx_log_error(NGX_LOG_ERR, log, 0, "%s: Discard req. body failed.
rc=%i", __FUNCTION__, rc);
    return rc;
  }

  r->err_status = http_status;
  r->headers_out.status = http_status;
  r->headers_out.content_length_n = buf->last - buf->pos;
  ngx_str_set(&r->headers_out.content_type, "text/plain");

  rc = ngx_http_send_header(r);

  if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
    ngx_log_error(NGX_LOG_ERR, log, 0, "%s: Send header failed. rc=%i",
__FUNCTION__, rc);
    return rc;
  }

  ngx_chain_t *out_chain = ngx_alloc_chain_link(r->pool);
  if (NULL == out_chain) {
    ngx_log_error(NGX_LOG_ERR, log, 0, "%s: Buffer chain alloc failed",
__FUNCTION__);
    return NGX_ERROR;
  }

  out_chain->buf = buf;
  out_chain->next = NULL;
  buf->last_buf = 1;
  buf->last_in_chain = 1;

  rc = ngx_http_output_filter(r, out_chain);
  if ((rc != NGX_OK) && (rc != NGX_AGAIN)) {
    ngx_log_error(NGX_LOG_ERR, log, 0, "%s: Output filter call failed.
rc=%i", __FUNCTION__, rc);
    return NGX_ERROR;
  }

  return NGX_OK;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20210810/1c71dc2e/attachment.htm>


More information about the nginx-devel mailing list