Ticket #1003: http2_socket_leak.patch

File http2_socket_leak.patch, 3.1 KB (added by Valentin V. Bartenev, 10 years ago)
  • src/http/v2/ngx_http_v2.c

    diff -r 6f69e3c0f780 -r a7e7afe80319 src/http/v2/ngx_http_v2.c
    a b ngx_http_v2_write_handler(ngx_event_t *w  
    410410
    411411    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http2 write handler");
    412412
     413    if (h2c->last_out == NULL && !c->buffered) {
     414        ngx_http_v2_handle_connection(h2c);
     415        return;
     416    }
     417
    413418    h2c->blocked = 1;
    414419
    415420    rc = ngx_http_v2_send_output_queue(h2c);
    … … ngx_http_v2_send_output_queue(ngx_http_v  
    468473    wev = c->write;
    469474
    470475    if (!wev->ready) {
    471         return NGX_OK;
     476        return NGX_AGAIN;
    472477    }
    473478
    474479    cl = NULL;
    … … ngx_http_v2_send_output_queue(ngx_http_v  
    488493                       out->blocked, out->length);
    489494    }
    490495
    491     cl = c->send_chain(c, cl, 0);
    492 
    493     if (cl == NGX_CHAIN_ERROR) {
     496    if (c->send_chain(c, cl, 0) == NGX_CHAIN_ERROR) {
    494497        goto error;
    495498    }
    496499
    … … ngx_http_v2_send_output_queue(ngx_http_v  
    539542        c->tcp_nodelay = NGX_TCP_NODELAY_SET;
    540543    }
    541544
    542     if (cl) {
    543         ngx_add_timer(wev, clcf->send_timeout);
    544 
    545     } else {
    546         if (wev->timer_set) {
    547             ngx_del_timer(wev);
    548         }
    549     }
    550 
    551545    for ( /* void */ ; out; out = fn) {
    552546        fn = out->next;
    553547
    … … ngx_http_v2_send_output_queue(ngx_http_v  
    572566
    573567    h2c->last_out = frame;
    574568
     569    if (frame || (c->buffered && !wev->ready)) {
     570        ngx_add_timer(wev, clcf->send_timeout);
     571        return NGX_AGAIN;
     572    }
     573
     574    if (wev->timer_set) {
     575        ngx_del_timer(wev);
     576    }
     577
    575578    return NGX_OK;
    576579
    577580error:
    … … error:  
    589592static void
    590593ngx_http_v2_handle_connection(ngx_http_v2_connection_t *h2c)
    591594{
    592     ngx_connection_t          *c;
     595    ngx_int_t                rc;
     596    ngx_connection_t        *c;
    593597    ngx_http_v2_srv_conf_t  *h2scf;
    594598
    595599    if (h2c->last_out || h2c->processing) {
    … … ngx_http_v2_handle_connection(ngx_http_v  
    604608    }
    605609
    606610    if (c->buffered) {
    607         return;
     611        h2c->blocked = 1;
     612
     613        rc = ngx_http_v2_send_output_queue(h2c);
     614
     615        h2c->blocked = 0;
     616
     617        if (rc != NGX_OK) {
     618            if (rc == NGX_ERROR) {
     619                ngx_http_close_connection(c);
     620            }
     621
     622            return;
     623        }
    608624    }
    609625
    610626    h2scf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx,
  • src/http/v2/ngx_http_v2_filter_module.c

    diff -r 6f69e3c0f780 -r a7e7afe80319 src/http/v2/ngx_http_v2_filter_module.c
    a b ngx_http_v2_header_filter(ngx_http_reque  
    165165        return NGX_OK;
    166166    }
    167167
     168    fc = r->connection;
     169
     170    if (fc->error) {
     171        return NGX_ERROR;
     172    }
     173
    168174    if (r->method == NGX_HTTP_HEAD) {
    169175        r->header_only = 1;
    170176    }
    … … ngx_http_v2_header_filter(ngx_http_reque  
    255261        len += 1 + ngx_http_v2_literal_size("Wed, 31 Dec 1986 18:00:00 GMT");
    256262    }
    257263
    258     fc = r->connection;
    259 
    260264    if (r->headers_out.location && r->headers_out.location->value.len) {
    261265
    262266        if (r->headers_out.location->value.data[0] == '/') {