changeset 9059:b87a0dbc1150 quic

HTTP/3: implement keepalive for hq. Previously, keepalive timer was deleted in ngx_http_v3_wait_request_handler() and set in request cleanup handler. This worked for HTTP/3 connections, but not for hq connections. Now keepalive timer is deleted in ngx_http_v3_init_request_stream() and set in connection cleanup handler, which works both for HTTP/3 and hq.
author Roman Arutyunyan <arut@nginx.com>
date Tue, 25 Oct 2022 12:52:09 +0400
parents b0c2234aaa9f
children 91ad1abfb285
files src/http/v3/ngx_http_v3_request.c
diffstat 1 files changed, 30 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/src/http/v3/ngx_http_v3_request.c
+++ b/src/http/v3/ngx_http_v3_request.c
@@ -12,6 +12,7 @@
 
 static void ngx_http_v3_init_request_stream(ngx_connection_t *c);
 static void ngx_http_v3_wait_request_handler(ngx_event_t *rev);
+static void ngx_http_v3_cleanup_connection(void *data);
 static void ngx_http_v3_cleanup_request(void *data);
 static void ngx_http_v3_process_request(ngx_event_t *rev);
 static ngx_int_t ngx_http_v3_process_header(ngx_http_request_t *r,
@@ -165,6 +166,7 @@ ngx_http_v3_init_request_stream(ngx_conn
     uint64_t                   n;
     ngx_event_t               *rev;
     ngx_connection_t          *pc;
+    ngx_pool_cleanup_t        *cln;
     ngx_http_connection_t     *hc;
     ngx_http_v3_session_t     *h3c;
     ngx_http_core_loc_conf_t  *clcf;
@@ -220,6 +222,21 @@ ngx_http_v3_init_request_stream(ngx_conn
                                         "reached maximum number of requests");
     }
 
+    cln = ngx_pool_cleanup_add(c->pool, 0);
+    if (cln == NULL) {
+        ngx_http_close_connection(c);
+        return;
+    }
+
+    cln->handler = ngx_http_v3_cleanup_connection;
+    cln->data = c;
+
+    h3c->nrequests++;
+
+    if (h3c->keepalive.timer_set) {
+        ngx_del_timer(&h3c->keepalive);
+    }
+
     rev = c->read;
 
 #if (NGX_HTTP_V3_HQ)
@@ -256,7 +273,6 @@ ngx_http_v3_wait_request_handler(ngx_eve
     ngx_connection_t          *c;
     ngx_pool_cleanup_t        *cln;
     ngx_http_request_t        *r;
-    ngx_http_v3_session_t     *h3c;
     ngx_http_connection_t     *hc;
     ngx_http_core_srv_conf_t  *cscf;
 
@@ -377,13 +393,6 @@ ngx_http_v3_wait_request_handler(ngx_eve
     cln->handler = ngx_http_v3_cleanup_request;
     cln->data = r;
 
-    h3c = ngx_http_v3_get_session(c);
-    h3c->nrequests++;
-
-    if (h3c->keepalive.timer_set) {
-        ngx_del_timer(&h3c->keepalive);
-    }
-
     rev->handler = ngx_http_v3_process_request;
     ngx_http_v3_process_request(rev);
 }
@@ -418,20 +427,13 @@ ngx_http_v3_reset_stream(ngx_connection_
 
 
 static void
-ngx_http_v3_cleanup_request(void *data)
+ngx_http_v3_cleanup_connection(void *data)
 {
-    ngx_http_request_t  *r = data;
+    ngx_connection_t  *c = data;
 
-    ngx_connection_t          *c;
     ngx_http_v3_session_t     *h3c;
     ngx_http_core_loc_conf_t  *clcf;
 
-    c = r->connection;
-
-    if (!r->response_sent) {
-        c->error = 1;
-    }
-
     h3c = ngx_http_v3_get_session(c);
 
     if (--h3c->nrequests == 0) {
@@ -442,6 +444,17 @@ ngx_http_v3_cleanup_request(void *data)
 
 
 static void
+ngx_http_v3_cleanup_request(void *data)
+{
+    ngx_http_request_t  *r = data;
+
+    if (!r->response_sent) {
+        r->connection->error = 1;
+    }
+}
+
+
+static void
 ngx_http_v3_process_request(ngx_event_t *rev)
 {
     u_char                       *p;