[PATCH 3 of 4] Silenced complaints about socket leaks on forced termination

Maxim Dounin mdounin at mdounin.ru
Mon Nov 27 02:50:26 UTC 2023


# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1701049787 -10800
#      Mon Nov 27 04:49:47 2023 +0300
# Node ID 61d08e4cf97cc073200ec32fc6ada9a2d48ffe51
# Parent  faf0b9defc76b8683af466f8a950c2c241382970
Silenced complaints about socket leaks on forced termination.

When graceful shutdown was requested, and then nginx was forced to
do fast shutdown, it used to (incorrectly) complain about open sockets
left in connections which weren't yet closed when fast shutdown
was requested.

Fix is to avoid complaining about open sockets when fast shutdown was
requested after graceful one.  Abnormal termination, if requested with
the WINCH signal, can still happen though.

diff --git a/src/os/unix/ngx_process_cycle.c b/src/os/unix/ngx_process_cycle.c
--- a/src/os/unix/ngx_process_cycle.c
+++ b/src/os/unix/ngx_process_cycle.c
@@ -948,7 +948,7 @@ ngx_worker_process_exit(ngx_cycle_t *cyc
         }
     }
 
-    if (ngx_exiting) {
+    if (ngx_exiting && !ngx_terminate) {
         c = cycle->connections;
         for (i = 0; i < cycle->connection_n; i++) {
             if (c[i].fd != -1
@@ -963,11 +963,11 @@ ngx_worker_process_exit(ngx_cycle_t *cyc
                 ngx_debug_quit = 1;
             }
         }
+    }
 
-        if (ngx_debug_quit) {
-            ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, "aborting");
-            ngx_debug_point();
-        }
+    if (ngx_debug_quit) {
+        ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, "aborting");
+        ngx_debug_point();
     }
 
     /*
diff --git a/src/os/win32/ngx_process_cycle.c b/src/os/win32/ngx_process_cycle.c
--- a/src/os/win32/ngx_process_cycle.c
+++ b/src/os/win32/ngx_process_cycle.c
@@ -834,7 +834,7 @@ ngx_worker_process_exit(ngx_cycle_t *cyc
         }
     }
 
-    if (ngx_exiting) {
+    if (ngx_exiting && !ngx_terminate) {
         c = cycle->connections;
         for (i = 0; i < cycle->connection_n; i++) {
             if (c[i].fd != (ngx_socket_t) -1


More information about the nginx-devel mailing list