diff src/http/v3/ngx_http_v3_request.c @ 9055:1192923be0aa quic

QUIC: idle mode for main connection. Now main QUIC connection for HTTP/3 always has c->idle flag set. This allows the connection to receive worker shutdown notification. It is passed to application level via a new conf->shutdown() callback. The HTTP/3 shutdown callback sends GOAWAY to client and gracefully shuts down the QUIC connection.
author Roman Arutyunyan <arut@nginx.com>
date Wed, 19 Oct 2022 17:45:18 +0400
parents 6546c2ae1c7b
children 7b83da3bdf9f
line wrap: on
line diff
--- a/src/http/v3/ngx_http_v3_request.c
+++ b/src/http/v3/ngx_http_v3_request.c
@@ -100,6 +100,37 @@ ngx_http_v3_init(ngx_connection_t *c)
 }
 
 
+void
+ngx_http_v3_shutdown(ngx_connection_t *c)
+{
+    ngx_http_v3_session_t  *h3c;
+
+    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 shutdown");
+
+    h3c = ngx_http_v3_get_session(c);
+
+    if (h3c == NULL) {
+        ngx_quic_finalize_connection(c, NGX_HTTP_V3_ERR_NO_ERROR,
+                                     "connection shutdown");
+        return;
+    }
+
+    if (!h3c->goaway) {
+        h3c->goaway = 1;
+
+#if (NGX_HTTP_V3_HQ)
+        if (!h3c->hq)
+#endif
+        {
+            (void) ngx_http_v3_send_goaway(c, h3c->next_request_id);
+        }
+
+        ngx_http_v3_shutdown_connection(c, NGX_HTTP_V3_ERR_NO_ERROR,
+                                        "connection shutdown");
+    }
+}
+
+
 static void
 ngx_http_v3_init_request_stream(ngx_connection_t *c)
 {
@@ -140,6 +171,8 @@ ngx_http_v3_init_request_stream(ngx_conn
 
     pc = c->quic->parent;
 
+    h3c->next_request_id = c->quic->id + 0x04;
+
     if (n + 1 == clcf->keepalive_requests
         || ngx_current_msec - pc->start_time > clcf->keepalive_time)
     {
@@ -149,7 +182,7 @@ ngx_http_v3_init_request_stream(ngx_conn
         if (!h3c->hq)
 #endif
         {
-            if (ngx_http_v3_send_goaway(c, (n + 1) << 2) != NGX_OK) {
+            if (ngx_http_v3_send_goaway(c, h3c->next_request_id) != NGX_OK) {
                 ngx_http_close_connection(c);
                 return;
             }