[PATCH] Core: stop trying to get TCP_DEFER_ACCEPT from unix sockets.

Maxim Dounin mdounin at mdounin.ru
Sat Oct 26 03:31:10 UTC 2013


Hello!

On Fri, Oct 25, 2013 at 03:57:24PM -0700, Piotr Sikora wrote:

> Hey Maxim,
> 
> > Any specific reason to?  It doesn't seems to fail / produce any
> > problems, and may even start working eventually.
> 
> On the contrary, the call used to succeed (tested with Linux 3.2),
> but recently started failing (tested with Linux 3.9), which results
> in errors produced during binary upgrade:
> 
> [notice] 1#0: getsockopt(TCP_DEFER_ACCEPT) for unix:/tmp/test.sock
> failed, ignored (95: Operation not supported)

Ok, fair enough.  Wouldn't something like this be better then 
(untested)?

# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1382758089 -14400
#      Sat Oct 26 07:28:09 2013 +0400
# Node ID b4a2dbe4527b274d3b87b8cdab8e1637c379a05a
# Parent  e6a1623f87bc96d5ec62b6d77356aa47dbc60756
Core: handling of getsockopt(TCP_DEFER_ACCEPT) failures.

Recent Linux versions started to return EOPNOTSUPP to getsockopt() calls
on unix sockets, resulting in log pollution on binary upgrade.  Silently
ignore such errors.

diff --git a/src/core/ngx_connection.c b/src/core/ngx_connection.c
--- a/src/core/ngx_connection.c
+++ b/src/core/ngx_connection.c
@@ -93,8 +93,10 @@ ngx_set_inherited_sockets(ngx_cycle_t *c
     ngx_uint_t                 i;
     ngx_listening_t           *ls;
     socklen_t                  olen;
+#if (NGX_HAVE_DEFERRED_ACCEPT)
+    ngx_err_t                  err;
+#endif
 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
-    ngx_err_t                  err;
     struct accept_filter_arg   af;
 #endif
 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
@@ -248,7 +250,13 @@ ngx_set_inherited_sockets(ngx_cycle_t *c
         if (getsockopt(ls[i].fd, IPPROTO_TCP, TCP_DEFER_ACCEPT, &timeout, &olen)
             == -1)
         {
-            ngx_log_error(NGX_LOG_NOTICE, cycle->log, ngx_errno,
+            err = ngx_errno;
+
+            if (err == NGX_EOPNOTSUPP) {
+                continue;
+            }
+
+            ngx_log_error(NGX_LOG_NOTICE, cycle->log, err,
                           "getsockopt(TCP_DEFER_ACCEPT) for %V failed, ignored",
                           &ls[i].addr_text);
             continue;
diff --git a/src/os/unix/ngx_errno.h b/src/os/unix/ngx_errno.h
--- a/src/os/unix/ngx_errno.h
+++ b/src/os/unix/ngx_errno.h
@@ -51,6 +51,7 @@ typedef int               ngx_err_t;
 #define NGX_ENOMOREFILES  0
 #define NGX_ELOOP         ELOOP
 #define NGX_EBADF         EBADF
+#define NGX_EOPNOTSUPP    EOPNOTSUPP
 
 #if (NGX_HAVE_OPENAT)
 #define NGX_EMLINK        EMLINK


-- 
Maxim Dounin
http://nginx.org/en/donation.html



More information about the nginx-devel mailing list