No functional changes.

 src/http/ngx_http_upstream.c |  91 ++++++++++++++++++++-----------------------
 1 files changed, 43 insertions(+), 48 deletions(-)


# HG changeset patch
# User Vladimir Khomutov <v...@wbsrv.ru>
# Date 1695647888 -10800
#      Mon Sep 25 16:18:08 2023 +0300
# Node ID 1fb8eae095661a3fa1ce5598528d81dddc0811a6
# Parent  f8275ecea4a7b18ae128f4e622ec50aa139cc6e1
Upstream: separate function to handle upstream connection closing.

No functional changes.

diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -98,6 +98,8 @@ static void ngx_http_upstream_dummy_hand
     ngx_http_upstream_t *u);
 static void ngx_http_upstream_next(ngx_http_request_t *r,
     ngx_http_upstream_t *u, ngx_uint_t ft_type);
+static void ngx_http_upstream_close_peer_connection(ngx_http_request_t *r,
+    ngx_http_upstream_t *u, ngx_uint_t no_send);
 static void ngx_http_upstream_cleanup(void *data);
 static void ngx_http_upstream_finalize_request(ngx_http_request_t *r,
     ngx_http_upstream_t *u, ngx_int_t rc);
@@ -4462,25 +4464,7 @@ ngx_http_upstream_next(ngx_http_request_
     }
 
     if (u->peer.connection) {
-        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
-                       "close http upstream connection: %d",
-                       u->peer.connection->fd);
-#if (NGX_HTTP_SSL)
-
-        if (u->peer.connection->ssl) {
-            u->peer.connection->ssl->no_wait_shutdown = 1;
-            u->peer.connection->ssl->no_send_shutdown = 1;
-
-            (void) ngx_ssl_shutdown(u->peer.connection);
-        }
-#endif
-
-        if (u->peer.connection->pool) {
-            ngx_destroy_pool(u->peer.connection->pool);
-        }
-
-        ngx_close_connection(u->peer.connection);
-        u->peer.connection = NULL;
+        ngx_http_upstream_close_peer_connection(r, u, 1);
     }
 
     ngx_http_upstream_connect(r, u);
@@ -4488,6 +4472,39 @@ ngx_http_upstream_next(ngx_http_request_
 
 
 static void
+ngx_http_upstream_close_peer_connection(ngx_http_request_t *r,
+    ngx_http_upstream_t *u, ngx_uint_t no_send)
+{
+    ngx_pool_t       *pool;
+    ngx_connection_t *c;
+
+    c = u->peer.connection;
+
+    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+                   "close http upstream connection: %d", c->fd);
+
+#if (NGX_HTTP_SSL)
+    if (c->ssl) {
+        c->ssl->no_wait_shutdown = 1;
+        c->ssl->no_send_shutdown = no_send;
+
+        (void) ngx_ssl_shutdown(c);
+    }
+#endif
+
+    pool = c->pool;
+
+    ngx_close_connection(c);
+
+    if (pool) {
+        ngx_destroy_pool(pool);
+    }
+
+    u->peer.connection = NULL;
+}
+
+
+static void
 ngx_http_upstream_cleanup(void *data)
 {
     ngx_http_request_t *r = data;
@@ -4544,37 +4561,15 @@ ngx_http_upstream_finalize_request(ngx_h
     }
 
     if (u->peer.connection) {
-
-#if (NGX_HTTP_SSL)
-
         /* TODO: do not shutdown persistent connection */
 
-        if (u->peer.connection->ssl) {
-
-            /*
-             * We send the "close notify" shutdown alert to the upstream only
-             * and do not wait its "close notify" shutdown alert.
-             * It is acceptable according to the TLS standard.
-             */
-
-            u->peer.connection->ssl->no_wait_shutdown = 1;
-
-            (void) ngx_ssl_shutdown(u->peer.connection);
-        }
-#endif
-
-        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
-                       "close http upstream connection: %d",
-                       u->peer.connection->fd);
-
-        if (u->peer.connection->pool) {
-            ngx_destroy_pool(u->peer.connection->pool);
-        }
-
-        ngx_close_connection(u->peer.connection);
-    }
-
-    u->peer.connection = NULL;
+        /*
+         * We send the "close notify" shutdown alert to the upstream only
+         * and do not wait its "close notify" shutdown alert.
+         * It is acceptable according to the TLS standard.
+         */
+        ngx_http_upstream_close_peer_connection(r, u, 0);
+    }
 
     if (u->pipe && u->pipe->temp_file) {
         ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel

Reply via email to