[PATCH 1 of 2] Core: connect() error log message made more verbose

Safar Safarly hafl at me.com
Wed Feb 8 15:54:06 UTC 2023


# HG changeset patch
# User Safar Safarly <hafl at me.com>
# Date 1675779866 -10800
#      Tue Feb 07 17:24:26 2023 +0300
# Node ID 55553146bd984be7e9e3bbfa851c282feda82d93
# Parent  cffaf3f2eec8fd33605c2a37814f5ffc30371989
Core: connect() error log message made more verbose

There was a major problem in logs: we could not identify to which servers
connect() has failed. Previously log produced:

    ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_socket_errno,
                  "connect() failed");

And now we'll have an address or unix socket in log:

    ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_socket_errno,
                  "connect() to %V failed", &peer->server.name);

Message format has chosen to be exact as it is used in ngx_event_connect.c:242
with similar error logging:

    ngx_log_error(level, c->log, err, "connect() to %V failed",
                  pc->name);

So everywhere connect() could fail we'd get a uniform and verbose error message
in log.

diff -r cffaf3f2eec8 -r 55553146bd98 src/core/ngx_resolver.c
--- a/src/core/ngx_resolver.c	Thu Feb 02 23:38:48 2023 +0300
+++ b/src/core/ngx_resolver.c	Tue Feb 07 17:24:26 2023 +0300
@@ -4512,7 +4512,7 @@
 
     if (rc == -1) {
         ngx_log_error(NGX_LOG_CRIT, &rec->log, ngx_socket_errno,
-                      "connect() failed");
+                      "connect() to %V failed", &rec->server);
 
         goto failed;
     }
diff -r cffaf3f2eec8 -r 55553146bd98 src/core/ngx_syslog.c
--- a/src/core/ngx_syslog.c	Thu Feb 02 23:38:48 2023 +0300
+++ b/src/core/ngx_syslog.c	Tue Feb 07 17:24:26 2023 +0300
@@ -337,7 +337,7 @@
 
     if (connect(fd, peer->server.sockaddr, peer->server.socklen) == -1) {
         ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_socket_errno,
-                      "connect() failed");
+                      "connect() to %V failed", &peer->server.name);
         goto failed;
     }
 


More information about the nginx-devel mailing list