src/http/ngx_http_upstream.c:993: error: Buffer Overrun S2
  Offset: [`ngx_current_msec`, +oo] Size: [0, +oo] by call to `ngx_http_upstream_connect`.

src/http/ngx_http_upstream.c:931:1: Global `ngx_current_msec`
929. 
930. 
931. static void
     ^
932. ngx_http_upstream_resolve_handler(ngx_resolver_ctx_t *ctx)
933. {

src/http/ngx_http_upstream.c:985:5: Assignment
983.     ur->ctx = NULL;
984. 
985.     u->peer.start_time = ngx_current_msec;
         ^
986. 
987.     if (u->conf->next_upstream_tries

src/http/ngx_http_upstream.c:993:5: Call
991.     }
992. 
993.     ngx_http_upstream_connect(r, u);
         ^
994. 
995. failed:

src/http/ngx_http_upstream.c:1236:1: Parameter `r->http_connection->nfree`
  1234. 
  1235. 
  1236. static void
        ^
  1237. ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u)
  1238. {

src/http/ngx_http_upstream.c:1253:9: Call
  1251.     u->state = ngx_array_push(r->upstream_states);
  1252.     if (u->state == NULL) {
  1253.         ngx_http_upstream_finalize_request(r, u,
                ^
  1254.                                            NGX_HTTP_INTERNAL_SERVER_ERROR);
  1255.         return;

src/http/ngx_http_upstream.c:3658:1: Parameter `r->http_connection->nfree`
    3656. 
    3657. 
    3658. static void
          ^
    3659. ngx_http_upstream_finalize_request(ngx_http_request_t *r,
    3660.     ngx_http_upstream_t *u, ngx_int_t rc)

src/http/ngx_http_upstream.c:3785:9: Call
    3783.         || rc == NGX_HTTP_CLIENT_CLOSED_REQUEST)
    3784.     {
    3785.         ngx_http_finalize_request(r, rc);
                  ^
    3786.         return;
    3787.     }

src/http/ngx_http_request.c:2252:1: Parameter `r->http_connection->nfree`
      2250. 
      2251. 
      2252. void
            ^
      2253. ngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc)
      2254. {

src/http/ngx_http_request.c:2437:5: Call
      2435.     }
      2436. 
      2437.     ngx_http_finalize_connection(r);
                ^
      2438. }
      2439. 

src/http/ngx_http_request.c:2501:1: Parameter `r->http_connection->nfree`
        2499. 
        2500. 
        2501. static void
              ^
        2502. ngx_http_finalize_connection(ngx_http_request_t *r)
        2503. {

src/http/ngx_http_request.c:2536:9: Call
        2534.          && clcf->keepalive_timeout > 0)
        2535.     {
        2536.         ngx_http_set_keepalive(r);
                      ^
        2537.         return;
        2538.     }

src/http/ngx_http_request.c:2827:1: <Offset trace>
2825. 
2826. 
2827. static void
      ^
2828. ngx_http_set_keepalive(ngx_http_request_t *r)
2829. {

src/http/ngx_http_request.c:2827:1: Parameter `r->http_connection->nfree`
          2825. 
          2826. 
          2827. static void
                ^
          2828. ngx_http_set_keepalive(ngx_http_request_t *r)
          2829. {

src/http/ngx_http_request.c:2827:1: <Length trace>
2825. 
2826. 
2827. static void
      ^
2828. ngx_http_set_keepalive(ngx_http_request_t *r)
2829. {

src/http/ngx_http_request.c:2827:1: Parameter `*r->http_connection->free`
          2825. 
          2826. 
          2827. static void
                ^
          2828. ngx_http_set_keepalive(ngx_http_request_t *r)
          2829. {

src/http/ngx_http_request.c:2886:17: Array access: Offset: [ngx_current_msec, +oo] Size: [0, +oo] by call to `ngx_http_upstream_connect` 
          2884.             for (i = 0; i < hc->nbusy - 1; i++) {
          2885.                 f = hc->busy[i];
          2886.                 hc->free[hc->nfree++] = f;
                                ^
          2887.                 f->pos = f->start;
          2888.                 f->last = f->start;

static void
ngx_http_set_keepalive(ngx_http_request_t *r)
{
    int                        tcp_nodelay;
    ngx_int_t                  i;
    ngx_buf_t                 *b, *f;
    ngx_event_t               *rev, *wev;
    ngx_connection_t          *c;
    ngx_http_connection_t     *hc;
    ngx_http_core_srv_conf_t  *cscf;
    ngx_http_core_loc_conf_t  *clcf;
    c = r->connection;
    rev = c->read;
    clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "set http keepalive handler");
    if (r->discard_body) {
        r->write_event_handler = ngx_http_request_empty_handler;
        r->lingering_time = ngx_time() + (time_t) (clcf->lingering_time / 1000);
        ngx_add_timer(rev, clcf->lingering_timeout);
        return;
    }
    c->log->action = "closing request";
    hc = r->http_connection;
    b = r->header_in;
    if (b->pos < b->last) {
        if (b != c->buffer) {
            cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
            if (hc->free == NULL) {
                hc->free = ngx_palloc(c->pool,
                  cscf->large_client_header_buffers.num * sizeof(ngx_buf_t *));
                if (hc->free == NULL) {
                    ngx_http_close_request(r, 0);
                    return;
                }
            }
            for (i = 0; i < hc->nbusy - 1; i++) {
                f = hc->busy[i];
                hc->free[hc->nfree++] = f;
                f->pos = f->start;
                f->last = f->start;
            }
            hc->busy[0] = b;
            hc->nbusy = 1;
        }
    }
    r->keepalive = 0;
    ngx_http_free_request(r, 0);
    c->data = hc;
    if (ngx_handle_read_event(rev, 0) != NGX_OK) {
        ngx_http_close_connection(c);
        return;
    }
    wev = c->write;
    wev->handler = ngx_http_empty_handler;
    if (b->pos < b->last) {
        ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "pipelined request");
        c->log->action = "reading client pipelined request line";
        r = ngx_http_create_request(c);
        if (r == NULL) {
            ngx_http_close_connection(c);
            return;
        }
        r->pipeline = 1;
        c->data = r;
        c->sent = 0;
        c->destroyed = 0;
        if (rev->timer_set) {
            ngx_del_timer(rev);
        }
        rev->handler = ngx_http_process_request_line;
        ngx_post_event(rev, &ngx_posted_events);
        return;
    }
    b = c->buffer;
    if (ngx_pfree(c->pool, b->start) == NGX_OK) {
        b->pos = NULL;
    } else {
        b->pos = b->start;
        b->last = b->start;
    }
    ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, "hc free: %p %d",
                   hc->free, hc->nfree);
    if (hc->free) {
        for (i = 0; i < hc->nfree; i++) {
            ngx_pfree(c->pool, hc->free[i]->start);
            hc->free[i] = NULL;
        }
        hc->nfree = 0;
    }
    ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, "hc busy: %p %d",
                   hc->busy, hc->nbusy);
    if (hc->busy) {
        for (i = 0; i < hc->nbusy; i++) {
            ngx_pfree(c->pool, hc->busy[i]->start);
            hc->busy[i] = NULL;
        }
        hc->nbusy = 0;
    }
#if (NGX_HTTP_SSL)
    if (c->ssl) {
        ngx_ssl_free_buffer(c);
    }
#endif
    rev->handler = ngx_http_keepalive_handler;
    if (wev->active && (ngx_event_flags & NGX_USE_LEVEL_EVENT)) {
        if (ngx_del_event(wev, NGX_WRITE_EVENT, 0) != NGX_OK) {
            ngx_http_close_connection(c);
            return;
        }
    }
    c->log->action = "keepalive";
    if (c->tcp_nopush == NGX_TCP_NOPUSH_SET) {
        if (ngx_tcp_push(c->fd) == -1) {
            ngx_connection_error(c, ngx_socket_errno, ngx_tcp_push_n " failed");
            ngx_http_close_connection(c);
            return;
        }
        c->tcp_nopush = NGX_TCP_NOPUSH_UNSET;
        tcp_nodelay = ngx_tcp_nodelay_and_tcp_nopush ? 1 : 0;
    } else {
        tcp_nodelay = 1;
    }
    if (tcp_nodelay
        && clcf->tcp_nodelay
        && c->tcp_nodelay == NGX_TCP_NODELAY_UNSET)
    {
        ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "tcp_nodelay");
        if (setsockopt(c->fd, IPPROTO_TCP, TCP_NODELAY,
                       (const void *) &tcp_nodelay, sizeof(int))
            == -1)
        {
#if (NGX_SOLARIS)
            c->log_error = NGX_ERROR_IGNORE_EINVAL;
#endif
            ngx_connection_error(c, ngx_socket_errno,
                                 "setsockopt(TCP_NODELAY) failed");
            c->log_error = NGX_ERROR_INFO;
            ngx_http_close_connection(c);
            return;
        }
        c->tcp_nodelay = NGX_TCP_NODELAY_SET;
    }
#if 0
    r->http_state = NGX_HTTP_KEEPALIVE_STATE;
#endif
    c->idle = 1;
    ngx_reusable_connection(c, 1);
    ngx_add_timer(rev, clcf->keepalive_timeout);
    if (rev->ready) {
        ngx_post_event(rev, &ngx_posted_events);
    }
}
['static void\nngx_http_upstream_resolve_handler(ngx_resolver_ctx_t *ctx)\n{\n    ngx_connection_t              *c;\n    ngx_http_request_t            *r;\n    ngx_http_upstream_t           *u;\n    ngx_http_upstream_resolved_t  *ur;\n    r = ctx->data;\n    c = r->connection;\n    u = r->upstream;\n    ur = u->resolved;\n    if (ctx->state) {\n        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,\n                      "%V could not be resolved (%i: %s)",\n                      &ctx->name, ctx->state,\n                      ngx_resolver_strerror(ctx->state));\n        ngx_http_upstream_finalize_request(r, u, NGX_HTTP_BAD_GATEWAY);\n        goto failed;\n    }\n    ur->naddrs = ctx->naddrs;\n    ur->addrs = ctx->addrs;\n#if (NGX_DEBUG)\n    {\n    u_char      text[NGX_SOCKADDR_STRLEN];\n    ngx_str_t   addr;\n    ngx_uint_t  i;\n    addr.data = text;\n    for (i = 0; i < ctx->naddrs; i++) {\n        addr.len = ngx_sock_ntop(ur->addrs[i].sockaddr, ur->addrs[i].socklen,\n                                 text, NGX_SOCKADDR_STRLEN, 0);\n        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n                       "name was resolved to %V", &addr);\n    }\n    }\n#endif\n    if (ngx_http_upstream_create_round_robin_peer(r, ur) != NGX_OK) {\n        ngx_http_upstream_finalize_request(r, u,\n                                           NGX_HTTP_INTERNAL_SERVER_ERROR);\n        goto failed;\n    }\n    ngx_resolve_name_done(ctx);\n    ur->ctx = NULL;\n    u->peer.start_time = ngx_current_msec;\n    if (u->conf->next_upstream_tries\n        && u->peer.tries > u->conf->next_upstream_tries)\n    {\n        u->peer.tries = u->conf->next_upstream_tries;\n    }\n    ngx_http_upstream_connect(r, u);\nfailed:\n    ngx_http_run_posted_requests(c);\n}', 'static void\nngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u)\n{\n    ngx_int_t          rc;\n    ngx_time_t        *tp;\n    ngx_connection_t  *c;\n    r->connection->log->action = "connecting to upstream";\n    if (u->state && u->state->response_sec) {\n        tp = ngx_timeofday();\n        u->state->response_sec = tp->sec - u->state->response_sec;\n        u->state->response_msec = tp->msec - u->state->response_msec;\n    }\n    u->state = ngx_array_push(r->upstream_states);\n    if (u->state == NULL) {\n        ngx_http_upstream_finalize_request(r, u,\n                                           NGX_HTTP_INTERNAL_SERVER_ERROR);\n        return;\n    }\n    ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t));\n    tp = ngx_timeofday();\n    u->state->response_sec = tp->sec;\n    u->state->response_msec = tp->msec;\n    rc = ngx_event_connect_peer(&u->peer);\n    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n                   "http upstream connect: %i", rc);\n    if (rc == NGX_ERROR) {\n        ngx_http_upstream_finalize_request(r, u,\n                                           NGX_HTTP_INTERNAL_SERVER_ERROR);\n        return;\n    }\n    u->state->peer = u->peer.name;\n    if (rc == NGX_BUSY) {\n        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "no live upstreams");\n        ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_NOLIVE);\n        return;\n    }\n    if (rc == NGX_DECLINED) {\n        ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);\n        return;\n    }\n    c = u->peer.connection;\n    c->data = r;\n    c->write->handler = ngx_http_upstream_handler;\n    c->read->handler = ngx_http_upstream_handler;\n    u->write_event_handler = ngx_http_upstream_send_request_handler;\n    u->read_event_handler = ngx_http_upstream_process_header;\n    c->sendfile &= r->connection->sendfile;\n    u->output.sendfile = c->sendfile;\n    if (c->pool == NULL) {\n        c->pool = ngx_create_pool(128, r->connection->log);\n        if (c->pool == NULL) {\n            ngx_http_upstream_finalize_request(r, u,\n                                               NGX_HTTP_INTERNAL_SERVER_ERROR);\n            return;\n        }\n    }\n    c->log = r->connection->log;\n    c->pool->log = c->log;\n    c->read->log = c->log;\n    c->write->log = c->log;\n    u->writer.out = NULL;\n    u->writer.last = &u->writer.out;\n    u->writer.connection = c;\n    u->writer.limit = 0;\n    if (u->request_sent) {\n        if (ngx_http_upstream_reinit(r, u) != NGX_OK) {\n            ngx_http_upstream_finalize_request(r, u,\n                                               NGX_HTTP_INTERNAL_SERVER_ERROR);\n            return;\n        }\n    }\n    if (r->request_body\n        && r->request_body->buf\n        && r->request_body->temp_file\n        && r == r->main)\n    {\n        u->output.free = ngx_alloc_chain_link(r->pool);\n        if (u->output.free == NULL) {\n            ngx_http_upstream_finalize_request(r, u,\n                                               NGX_HTTP_INTERNAL_SERVER_ERROR);\n            return;\n        }\n        u->output.free->buf = r->request_body->buf;\n        u->output.free->next = NULL;\n        u->output.allocated = 1;\n        r->request_body->buf->pos = r->request_body->buf->start;\n        r->request_body->buf->last = r->request_body->buf->start;\n        r->request_body->buf->tag = u->output.tag;\n    }\n    u->request_sent = 0;\n    if (rc == NGX_AGAIN) {\n        ngx_add_timer(c->write, u->conf->connect_timeout);\n        return;\n    }\n#if (NGX_HTTP_SSL)\n    if (u->ssl && c->ssl == NULL) {\n        ngx_http_upstream_ssl_init_connection(r, u, c);\n        return;\n    }\n#endif\n    ngx_http_upstream_send_request(r, u);\n}', 'static void\nngx_http_upstream_finalize_request(ngx_http_request_t *r,\n    ngx_http_upstream_t *u, ngx_int_t rc)\n{\n    ngx_uint_t   flush;\n    ngx_time_t  *tp;\n    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n                   "finalize http upstream request: %i", rc);\n    if (u->cleanup) {\n        *u->cleanup = NULL;\n        u->cleanup = NULL;\n    }\n    if (u->resolved && u->resolved->ctx) {\n        ngx_resolve_name_done(u->resolved->ctx);\n        u->resolved->ctx = NULL;\n    }\n    if (u->state && u->state->response_sec) {\n        tp = ngx_timeofday();\n        u->state->response_sec = tp->sec - u->state->response_sec;\n        u->state->response_msec = tp->msec - u->state->response_msec;\n        if (u->pipe && u->pipe->read_length) {\n            u->state->response_length = u->pipe->read_length;\n        }\n    }\n    u->finalize_request(r, rc);\n    if (u->peer.free && u->peer.sockaddr) {\n        u->peer.free(&u->peer, u->peer.data, 0);\n        u->peer.sockaddr = NULL;\n    }\n    if (u->peer.connection) {\n#if (NGX_HTTP_SSL)\n        if (u->peer.connection->ssl) {\n            u->peer.connection->ssl->no_wait_shutdown = 1;\n            (void) ngx_ssl_shutdown(u->peer.connection);\n        }\n#endif\n        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n                       "close http upstream connection: %d",\n                       u->peer.connection->fd);\n        if (u->peer.connection->pool) {\n            ngx_destroy_pool(u->peer.connection->pool);\n        }\n        ngx_close_connection(u->peer.connection);\n    }\n    u->peer.connection = NULL;\n    if (u->pipe && u->pipe->temp_file) {\n        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n                       "http upstream temp fd: %d",\n                       u->pipe->temp_file->file.fd);\n    }\n    if (u->store && u->pipe && u->pipe->temp_file\n        && u->pipe->temp_file->file.fd != NGX_INVALID_FILE)\n    {\n        if (ngx_delete_file(u->pipe->temp_file->file.name.data)\n            == NGX_FILE_ERROR)\n        {\n            ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,\n                          ngx_delete_file_n " \\"%s\\" failed",\n                          u->pipe->temp_file->file.name.data);\n        }\n    }\n#if (NGX_HTTP_CACHE)\n    if (r->cache) {\n        if (u->cacheable) {\n            if (rc == NGX_HTTP_BAD_GATEWAY || rc == NGX_HTTP_GATEWAY_TIME_OUT) {\n                time_t  valid;\n                valid = ngx_http_file_cache_valid(u->conf->cache_valid, rc);\n                if (valid) {\n                    r->cache->valid_sec = ngx_time() + valid;\n                    r->cache->error = rc;\n                }\n            }\n        }\n        ngx_http_file_cache_free(r->cache, u->pipe->temp_file);\n    }\n#endif\n    if (r->subrequest_in_memory\n        && u->headers_in.status_n >= NGX_HTTP_SPECIAL_RESPONSE)\n    {\n        u->buffer.last = u->buffer.pos;\n    }\n    if (rc == NGX_DECLINED) {\n        return;\n    }\n    r->connection->log->action = "sending to client";\n    if (!u->header_sent\n        || rc == NGX_HTTP_REQUEST_TIME_OUT\n        || rc == NGX_HTTP_CLIENT_CLOSED_REQUEST)\n    {\n        ngx_http_finalize_request(r, rc);\n        return;\n    }\n    flush = 0;\n    if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {\n        rc = NGX_ERROR;\n        flush = 1;\n    }\n    if (r->header_only) {\n        ngx_http_finalize_request(r, rc);\n        return;\n    }\n    if (rc == 0) {\n        rc = ngx_http_send_special(r, NGX_HTTP_LAST);\n    } else if (flush) {\n        r->keepalive = 0;\n        rc = ngx_http_send_special(r, NGX_HTTP_FLUSH);\n    }\n    ngx_http_finalize_request(r, rc);\n}', 'void\nngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc)\n{\n    ngx_connection_t          *c;\n    ngx_http_request_t        *pr;\n    ngx_http_core_loc_conf_t  *clcf;\n    c = r->connection;\n    ngx_log_debug5(NGX_LOG_DEBUG_HTTP, c->log, 0,\n                   "http finalize request: %d, \\"%V?%V\\" a:%d, c:%d",\n                   rc, &r->uri, &r->args, r == c->data, r->main->count);\n    if (rc == NGX_DONE) {\n        ngx_http_finalize_connection(r);\n        return;\n    }\n    if (rc == NGX_OK && r->filter_finalize) {\n        c->error = 1;\n    }\n    if (rc == NGX_DECLINED) {\n        r->content_handler = NULL;\n        r->write_event_handler = ngx_http_core_run_phases;\n        ngx_http_core_run_phases(r);\n        return;\n    }\n    if (r != r->main && r->post_subrequest) {\n        rc = r->post_subrequest->handler(r, r->post_subrequest->data, rc);\n    }\n    if (rc == NGX_ERROR\n        || rc == NGX_HTTP_REQUEST_TIME_OUT\n        || rc == NGX_HTTP_CLIENT_CLOSED_REQUEST\n        || c->error)\n    {\n        if (ngx_http_post_action(r) == NGX_OK) {\n            return;\n        }\n        if (r->main->blocked) {\n            r->write_event_handler = ngx_http_request_finalizer;\n        }\n        ngx_http_terminate_request(r, rc);\n        return;\n    }\n    if (rc >= NGX_HTTP_SPECIAL_RESPONSE\n        || rc == NGX_HTTP_CREATED\n        || rc == NGX_HTTP_NO_CONTENT)\n    {\n        if (rc == NGX_HTTP_CLOSE) {\n            ngx_http_terminate_request(r, rc);\n            return;\n        }\n        if (r == r->main) {\n            if (c->read->timer_set) {\n                ngx_del_timer(c->read);\n            }\n            if (c->write->timer_set) {\n                ngx_del_timer(c->write);\n            }\n        }\n        c->read->handler = ngx_http_request_handler;\n        c->write->handler = ngx_http_request_handler;\n        ngx_http_finalize_request(r, ngx_http_special_response_handler(r, rc));\n        return;\n    }\n    if (r != r->main) {\n        if (r->buffered || r->postponed) {\n            if (ngx_http_set_write_handler(r) != NGX_OK) {\n                ngx_http_terminate_request(r, 0);\n            }\n            return;\n        }\n        pr = r->parent;\n        if (r == c->data) {\n            r->main->count--;\n            r->main->subrequests++;\n            if (!r->logged) {\n                clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n                if (clcf->log_subrequest) {\n                    ngx_http_log_request(r);\n                }\n                r->logged = 1;\n            } else {\n                ngx_log_error(NGX_LOG_ALERT, c->log, 0,\n                              "subrequest: \\"%V?%V\\" logged again",\n                              &r->uri, &r->args);\n            }\n            r->done = 1;\n            if (pr->postponed && pr->postponed->request == r) {\n                pr->postponed = pr->postponed->next;\n            }\n            c->data = pr;\n        } else {\n            ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,\n                           "http finalize non-active request: \\"%V?%V\\"",\n                           &r->uri, &r->args);\n            r->write_event_handler = ngx_http_request_finalizer;\n            if (r->waited) {\n                r->done = 1;\n            }\n        }\n        if (ngx_http_post_request(pr, NULL) != NGX_OK) {\n            r->main->count++;\n            ngx_http_terminate_request(r, 0);\n            return;\n        }\n        ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,\n                       "http wake parent request: \\"%V?%V\\"",\n                       &pr->uri, &pr->args);\n        return;\n    }\n    if (r->buffered || c->buffered || r->postponed || r->blocked) {\n        if (ngx_http_set_write_handler(r) != NGX_OK) {\n            ngx_http_terminate_request(r, 0);\n        }\n        return;\n    }\n    if (r != c->data) {\n        ngx_log_error(NGX_LOG_ALERT, c->log, 0,\n                      "http finalize non-active request: \\"%V?%V\\"",\n                      &r->uri, &r->args);\n        return;\n    }\n    r->done = 1;\n    r->write_event_handler = ngx_http_request_empty_handler;\n    if (!r->post_action) {\n        r->request_complete = 1;\n    }\n    if (ngx_http_post_action(r) == NGX_OK) {\n        return;\n    }\n    if (c->read->timer_set) {\n        ngx_del_timer(c->read);\n    }\n    if (c->write->timer_set) {\n        c->write->delayed = 0;\n        ngx_del_timer(c->write);\n    }\n    if (c->read->eof) {\n        ngx_http_close_request(r, 0);\n        return;\n    }\n    ngx_http_finalize_connection(r);\n}', 'static void\nngx_http_finalize_connection(ngx_http_request_t *r)\n{\n    ngx_http_core_loc_conf_t  *clcf;\n#if (NGX_HTTP_SPDY)\n    if (r->spdy_stream) {\n        ngx_http_close_request(r, 0);\n        return;\n    }\n#endif\n    clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n    if (r->main->count != 1) {\n        if (r->discard_body) {\n            r->read_event_handler = ngx_http_discarded_request_body_handler;\n            ngx_add_timer(r->connection->read, clcf->lingering_timeout);\n            if (r->lingering_time == 0) {\n                r->lingering_time = ngx_time()\n                                      + (time_t) (clcf->lingering_time / 1000);\n            }\n        }\n        ngx_http_close_request(r, 0);\n        return;\n    }\n    if (!ngx_terminate\n         && !ngx_exiting\n         && r->keepalive\n         && clcf->keepalive_timeout > 0)\n    {\n        ngx_http_set_keepalive(r);\n        return;\n    }\n    if (clcf->lingering_close == NGX_HTTP_LINGERING_ALWAYS\n        || (clcf->lingering_close == NGX_HTTP_LINGERING_ON\n            && (r->lingering_close\n                || r->header_in->pos < r->header_in->last\n                || r->connection->read->ready)))\n    {\n        ngx_http_set_lingering_close(r);\n        return;\n    }\n    ngx_http_close_request(r, 0);\n}', 'static void\nngx_http_set_keepalive(ngx_http_request_t *r)\n{\n    int                        tcp_nodelay;\n    ngx_int_t                  i;\n    ngx_buf_t                 *b, *f;\n    ngx_event_t               *rev, *wev;\n    ngx_connection_t          *c;\n    ngx_http_connection_t     *hc;\n    ngx_http_core_srv_conf_t  *cscf;\n    ngx_http_core_loc_conf_t  *clcf;\n    c = r->connection;\n    rev = c->read;\n    clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "set http keepalive handler");\n    if (r->discard_body) {\n        r->write_event_handler = ngx_http_request_empty_handler;\n        r->lingering_time = ngx_time() + (time_t) (clcf->lingering_time / 1000);\n        ngx_add_timer(rev, clcf->lingering_timeout);\n        return;\n    }\n    c->log->action = "closing request";\n    hc = r->http_connection;\n    b = r->header_in;\n    if (b->pos < b->last) {\n        if (b != c->buffer) {\n            cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);\n            if (hc->free == NULL) {\n                hc->free = ngx_palloc(c->pool,\n                  cscf->large_client_header_buffers.num * sizeof(ngx_buf_t *));\n                if (hc->free == NULL) {\n                    ngx_http_close_request(r, 0);\n                    return;\n                }\n            }\n            for (i = 0; i < hc->nbusy - 1; i++) {\n                f = hc->busy[i];\n                hc->free[hc->nfree++] = f;\n                f->pos = f->start;\n                f->last = f->start;\n            }\n            hc->busy[0] = b;\n            hc->nbusy = 1;\n        }\n    }\n    r->keepalive = 0;\n    ngx_http_free_request(r, 0);\n    c->data = hc;\n    if (ngx_handle_read_event(rev, 0) != NGX_OK) {\n        ngx_http_close_connection(c);\n        return;\n    }\n    wev = c->write;\n    wev->handler = ngx_http_empty_handler;\n    if (b->pos < b->last) {\n        ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "pipelined request");\n        c->log->action = "reading client pipelined request line";\n        r = ngx_http_create_request(c);\n        if (r == NULL) {\n            ngx_http_close_connection(c);\n            return;\n        }\n        r->pipeline = 1;\n        c->data = r;\n        c->sent = 0;\n        c->destroyed = 0;\n        if (rev->timer_set) {\n            ngx_del_timer(rev);\n        }\n        rev->handler = ngx_http_process_request_line;\n        ngx_post_event(rev, &ngx_posted_events);\n        return;\n    }\n    b = c->buffer;\n    if (ngx_pfree(c->pool, b->start) == NGX_OK) {\n        b->pos = NULL;\n    } else {\n        b->pos = b->start;\n        b->last = b->start;\n    }\n    ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, "hc free: %p %d",\n                   hc->free, hc->nfree);\n    if (hc->free) {\n        for (i = 0; i < hc->nfree; i++) {\n            ngx_pfree(c->pool, hc->free[i]->start);\n            hc->free[i] = NULL;\n        }\n        hc->nfree = 0;\n    }\n    ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, "hc busy: %p %d",\n                   hc->busy, hc->nbusy);\n    if (hc->busy) {\n        for (i = 0; i < hc->nbusy; i++) {\n            ngx_pfree(c->pool, hc->busy[i]->start);\n            hc->busy[i] = NULL;\n        }\n        hc->nbusy = 0;\n    }\n#if (NGX_HTTP_SSL)\n    if (c->ssl) {\n        ngx_ssl_free_buffer(c);\n    }\n#endif\n    rev->handler = ngx_http_keepalive_handler;\n    if (wev->active && (ngx_event_flags & NGX_USE_LEVEL_EVENT)) {\n        if (ngx_del_event(wev, NGX_WRITE_EVENT, 0) != NGX_OK) {\n            ngx_http_close_connection(c);\n            return;\n        }\n    }\n    c->log->action = "keepalive";\n    if (c->tcp_nopush == NGX_TCP_NOPUSH_SET) {\n        if (ngx_tcp_push(c->fd) == -1) {\n            ngx_connection_error(c, ngx_socket_errno, ngx_tcp_push_n " failed");\n            ngx_http_close_connection(c);\n            return;\n        }\n        c->tcp_nopush = NGX_TCP_NOPUSH_UNSET;\n        tcp_nodelay = ngx_tcp_nodelay_and_tcp_nopush ? 1 : 0;\n    } else {\n        tcp_nodelay = 1;\n    }\n    if (tcp_nodelay\n        && clcf->tcp_nodelay\n        && c->tcp_nodelay == NGX_TCP_NODELAY_UNSET)\n    {\n        ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "tcp_nodelay");\n        if (setsockopt(c->fd, IPPROTO_TCP, TCP_NODELAY,\n                       (const void *) &tcp_nodelay, sizeof(int))\n            == -1)\n        {\n#if (NGX_SOLARIS)\n            c->log_error = NGX_ERROR_IGNORE_EINVAL;\n#endif\n            ngx_connection_error(c, ngx_socket_errno,\n                                 "setsockopt(TCP_NODELAY) failed");\n            c->log_error = NGX_ERROR_INFO;\n            ngx_http_close_connection(c);\n            return;\n        }\n        c->tcp_nodelay = NGX_TCP_NODELAY_SET;\n    }\n#if 0\n    r->http_state = NGX_HTTP_KEEPALIVE_STATE;\n#endif\n    c->idle = 1;\n    ngx_reusable_connection(c, 1);\n    ngx_add_timer(rev, clcf->keepalive_timeout);\n    if (rev->ready) {\n        ngx_post_event(rev, &ngx_posted_events);\n    }\n}']