[PATCH 2 of 8] QUIC: ngx_quic_terminate_connection() function

Roman Arutyunyan arut at nginx.com
Thu Jun 23 15:58:40 UTC 2022


# HG changeset patch
# User Roman Arutyunyan <arut at nginx.com>
# Date 1655903226 -14400
#      Wed Jun 22 17:07:06 2022 +0400
# Branch quic
# Node ID 5edae53d1fbfcd2eedab36252d9a2522dce5c3c8
# Parent  951d7116f37dc39d9eba20ceae49434592ce4677
QUIC: ngx_quic_terminate_connection() function.

Previously, ngx_quic_finalize_connection() terminated the connection.
Now it shuts down the connection gracefully with a close timeout.
The new function terminates the connection now.

diff --git a/src/event/quic/ngx_event_quic.c b/src/event/quic/ngx_event_quic.c
--- a/src/event/quic/ngx_event_quic.c
+++ b/src/event/quic/ngx_event_quic.c
@@ -416,6 +416,7 @@ ngx_quic_input_handler(ngx_event_t *rev)
     }
 
     if (c->close) {
+        qc->error = NGX_QUIC_ERR_NO_ERROR;
         qc->error_reason = "graceful shutdown";
         ngx_quic_close_connection(c, NGX_OK);
         return;
@@ -508,31 +509,26 @@ ngx_quic_close_connection(ngx_connection
             qc->error_level = c->ssl ? SSL_quic_read_level(c->ssl->connection)
                                      : ssl_encryption_initial;
 
+            if (qc->error == (ngx_uint_t) -1) {
+                qc->error = NGX_QUIC_ERR_INTERNAL_ERROR;
+                qc->error_app = 0;
+            }
+
+            ngx_log_debug5(NGX_LOG_DEBUG_EVENT, c->log, 0,
+                           "quic close immediate term:%d drain:%d "
+                           "%serror:%ui \"%s\"",
+                           rc == NGX_ERROR ? 1 : 0, qc->draining,
+                           qc->error_app ? "app " : "", qc->error,
+                           qc->error_reason ? qc->error_reason : "");
+
             if (rc == NGX_OK) {
-                ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0,
-                               "quic close immediate drain:%d",
-                               qc->draining);
-
                 qc->close.log = c->log;
                 qc->close.data = c;
                 qc->close.handler = ngx_quic_close_timer_handler;
                 qc->close.cancelable = 1;
 
                 ctx = ngx_quic_get_send_ctx(qc, qc->error_level);
-
                 ngx_add_timer(&qc->close, 3 * ngx_quic_pto(c, ctx));
-
-                qc->error = NGX_QUIC_ERR_NO_ERROR;
-
-            } else {
-                if (qc->error == (ngx_uint_t) -1 && !qc->error_app) {
-                    qc->error = NGX_QUIC_ERR_INTERNAL_ERROR;
-                }
-
-                ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
-                               "quic close immediate due to %serror: %ui %s",
-                               qc->error_app ? "app " : "", qc->error,
-                               qc->error_reason ? qc->error_reason : "");
             }
 
             (void) ngx_quic_send_cc(c);
@@ -608,6 +604,22 @@ quic_done:
 
 
 void
+ngx_quic_terminate_connection(ngx_connection_t *c, ngx_uint_t err,
+    const char *reason)
+{
+    ngx_quic_connection_t  *qc;
+
+    qc = ngx_quic_get_connection(c);
+    qc->error = err;
+    qc->error_reason = reason;
+    qc->error_app = 1;
+    qc->error_ftype = 0;
+
+    ngx_quic_close_connection(c, NGX_ERROR);
+}
+
+
+void
 ngx_quic_finalize_connection(ngx_connection_t *c, ngx_uint_t err,
     const char *reason)
 {
@@ -619,7 +631,7 @@ ngx_quic_finalize_connection(ngx_connect
     qc->error_app = 1;
     qc->error_ftype = 0;
 
-    ngx_quic_close_connection(c, NGX_ERROR);
+    ngx_quic_close_connection(c, NGX_OK);
 }
 
 
diff --git a/src/event/quic/ngx_event_quic.h b/src/event/quic/ngx_event_quic.h
--- a/src/event/quic/ngx_event_quic.h
+++ b/src/event/quic/ngx_event_quic.h
@@ -107,6 +107,8 @@ void ngx_quic_rbtree_insert_value(ngx_rb
     ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel);
 void ngx_quic_run(ngx_connection_t *c, ngx_quic_conf_t *conf);
 ngx_connection_t *ngx_quic_open_stream(ngx_connection_t *c, ngx_uint_t bidi);
+void ngx_quic_terminate_connection(ngx_connection_t *c, ngx_uint_t err,
+    const char *reason);
 void ngx_quic_finalize_connection(ngx_connection_t *c, ngx_uint_t err,
     const char *reason);
 void ngx_quic_shutdown_connection(ngx_connection_t *c, ngx_uint_t err,



More information about the nginx-devel mailing list