]> git.kaiwu.me - nginx.git/commitdiff
Respect QUIC max_idle_timeout.
authorRoman Arutyunyan <arut@nginx.com>
Mon, 23 Mar 2020 18:20:20 +0000 (21:20 +0300)
committerRoman Arutyunyan <arut@nginx.com>
Mon, 23 Mar 2020 18:20:20 +0000 (21:20 +0300)
src/event/ngx_event_quic.c
src/event/ngx_event_quic.h
src/http/ngx_http_request.c
src/http/v3/ngx_http_v3_module.c

index 582d3f8ce834085450d5e02bd72e7ccdbba2e517..a4a293a141be7911a1bd13f2cf37a8f14f2f02e1 100644 (file)
@@ -30,7 +30,6 @@ typedef struct {
 typedef struct {
     ngx_rbtree_t                      tree;
     ngx_rbtree_node_t                 sentinel;
-    ngx_msec_t                        timeout;
     ngx_connection_handler_pt         handler;
 
     ngx_uint_t                        id_counter;
@@ -59,6 +58,8 @@ struct ngx_quic_connection_s {
 
     ngx_quic_streams_t                streams;
     ngx_uint_t                        max_data;
+    ngx_uint_t                        send_timer_set;
+                                              /* unsigned  send_timer_set:1 */
 
 #define SSL_ECRYPTION_LAST ((ssl_encryption_application) + 1)
     uint64_t                          crypto_offset[SSL_ECRYPTION_LAST];
@@ -255,6 +256,12 @@ ngx_quic_add_handshake_data(ngx_ssl_conn_t *ssl_conn,
                 return NGX_ERROR;
             }
 
+            if (qc->ctp.max_idle_timeout > 0
+                && qc->ctp.max_idle_timeout < qc->tp.max_idle_timeout)
+            {
+                qc->tp.max_idle_timeout = qc->ctp.max_idle_timeout;
+            }
+
             qc->client_tp_done = 1;
         }
     }
@@ -334,7 +341,7 @@ ngx_quic_send_alert(ngx_ssl_conn_t *ssl_conn, enum ssl_encryption_level_t level,
 
 void
 ngx_quic_run(ngx_connection_t *c, ngx_ssl_t *ssl, ngx_quic_tp_t *tp,
-    ngx_msec_t timeout, ngx_connection_handler_pt handler)
+    ngx_connection_handler_pt handler)
 {
     ngx_buf_t          *b;
     ngx_quic_header_t   pkt;
@@ -359,9 +366,8 @@ ngx_quic_run(ngx_connection_t *c, ngx_ssl_t *ssl, ngx_quic_tp_t *tp,
 
     // we don't need stream handler for initial packet processing
     c->quic->streams.handler = handler;
-    c->quic->streams.timeout = timeout;
 
-    ngx_add_timer(c->read, timeout);
+    ngx_add_timer(c->read, c->quic->tp.max_idle_timeout);
 
     c->read->handler = ngx_quic_input_handler;
 
@@ -524,9 +530,10 @@ ngx_quic_init_connection(ngx_connection_t *c)
 static void
 ngx_quic_input_handler(ngx_event_t *rev)
 {
-    ssize_t            n;
-    ngx_buf_t          b;
-    ngx_connection_t  *c;
+    ssize_t                 n;
+    ngx_buf_t               b;
+    ngx_connection_t       *c;
+    ngx_quic_connection_t  *qc;
 
     static u_char      buf[65535];
 
@@ -544,8 +551,6 @@ ngx_quic_input_handler(ngx_event_t *rev)
         return;
     }
 
-    ngx_add_timer(rev, c->quic->streams.timeout);
-
     if (c->close) {
         ngx_quic_close_connection(c);
         return;
@@ -569,6 +574,11 @@ ngx_quic_input_handler(ngx_event_t *rev)
         ngx_quic_close_connection(c);
         return;
     }
+
+    qc = c->quic;
+
+    qc->send_timer_set = 0;
+    ngx_add_timer(rev, qc->tp.max_idle_timeout);
 }
 
 
@@ -1209,6 +1219,11 @@ ngx_quic_output(ngx_connection_t *c)
 
     qc->frames = NULL;
 
+    if (!qc->send_timer_set) {
+        qc->send_timer_set = 1;
+        ngx_add_timer(c->read, qc->tp.max_idle_timeout);
+    }
+
     return NGX_OK;
 }
 
index c174bfe449e9b6987b8cc502b3f9d0f39ee37932..1f022c6782eadea5596b5bb7df4591ebd1bfb9c7 100644 (file)
@@ -54,7 +54,7 @@ struct ngx_quic_stream_s {
 
 
 void ngx_quic_run(ngx_connection_t *c, ngx_ssl_t *ssl, ngx_quic_tp_t *tp,
-    ngx_msec_t timeout, ngx_connection_handler_pt handler);
+    ngx_connection_handler_pt handler);
 ngx_connection_t *ngx_quic_create_uni_stream(ngx_connection_t *c);
 
 
index 6c9fdc5434de54fad97c4b1b8d205f1e18cb8229..acd708cf67fa5c6899981dd0cb32edbe4821cb95 100644 (file)
@@ -347,9 +347,7 @@ ngx_http_init_connection(ngx_connection_t *c)
         v3cf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_v3_module);
         sscf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_ssl_module);
 
-        ngx_quic_run(c, &sscf->ssl, &v3cf->quic,
-                     c->listening->post_accept_timeout,
-                     ngx_http_quic_stream_handler);
+        ngx_quic_run(c, &sscf->ssl, &v3cf->quic, ngx_http_quic_stream_handler);
         return;
     }
 #endif
index 385838df4b2f21ea622333aa05a301b732029480..45bfc5b1c745d40c00e57f750b9efd643b28dcba 100644 (file)
@@ -229,7 +229,7 @@ ngx_http_v3_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
     ngx_http_v3_srv_conf_t *conf = child;
 
     ngx_conf_merge_msec_value(conf->quic.max_idle_timeout,
-                              prev->quic.max_idle_timeout, 10000);
+                              prev->quic.max_idle_timeout, 60000);
 
     // > 2 ^ 14 is invalid
     ngx_conf_merge_msec_value(conf->quic.max_ack_delay,