You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by co...@apache.org on 2018/01/04 15:10:45 UTC

svn commit: r1820098 - in /httpd/httpd/trunk: CHANGES docs/manual/mod/mpm_common.xml include/ap_listen.h os/unix/unixd.c server/listen.c server/mpm/event/event.c server/mpm/motorz/motorz.c server/mpm/prefork/prefork.c server/mpm/worker/worker.c

Author: covener
Date: Thu Jan  4 15:10:45 2018
New Revision: 1820098

URL: http://svn.apache.org/viewvc?rev=1820098&view=rev
Log:
Add "AcceptErrorsNonFatal" directive

This tweaks accept() failure processing by having ap_unixd_accept
pass more errors up, and having the MPM's check against a macro
to see if they are in a whitelist of non ENETDOWN/EMFILE kind 
of potential process-wide errors.

Default behavior is still to exit.


Modified:
    httpd/httpd/trunk/CHANGES
    httpd/httpd/trunk/docs/manual/mod/mpm_common.xml
    httpd/httpd/trunk/include/ap_listen.h
    httpd/httpd/trunk/os/unix/unixd.c
    httpd/httpd/trunk/server/listen.c
    httpd/httpd/trunk/server/mpm/event/event.c
    httpd/httpd/trunk/server/mpm/motorz/motorz.c
    httpd/httpd/trunk/server/mpm/prefork/prefork.c
    httpd/httpd/trunk/server/mpm/worker/worker.c

Modified: httpd/httpd/trunk/CHANGES
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/CHANGES?rev=1820098&r1=1820097&r2=1820098&view=diff
==============================================================================
--- httpd/httpd/trunk/CHANGES [utf-8] (original)
+++ httpd/httpd/trunk/CHANGES [utf-8] Thu Jan  4 15:10:45 2018
@@ -1,6 +1,11 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache 2.5.1
 
+
+  *) core: Add "AcceptErrorsNonFatal" to allow ECONNREFUSED, ECONNABORTED, and
+     ECONNRESET during the client accept() to not trigger graceful shutdown of
+     the child process.  [Eric Covener]
+
   *) mod_md v1.1.7:
      - MDMustStaple was unable to create the necessary OpenSSL OBJ identifier on some platforms, 
        possibly because this fails if the OID is already configured in ```openssl.cnf```, see

Modified: httpd/httpd/trunk/docs/manual/mod/mpm_common.xml
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/mod/mpm_common.xml?rev=1820098&r1=1820097&r2=1820098&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/mod/mpm_common.xml (original)
+++ httpd/httpd/trunk/docs/manual/mod/mpm_common.xml Thu Jan  4 15:10:45 2018
@@ -873,4 +873,35 @@ client connections</description>
 </usage>
 </directivesynopsis>
 
+<directivesynopsis>
+<name>AcceptErrorsNonFatal</name>
+<description>Treat some errors accepting a new connection as non-fatal
+to the httpd process.</description>
+<syntax>AcceptErrorsNonFatal ON</syntax>
+<default>OFF (ECONNREFUSED, ECONNABORTED, ECONNRESET cause the process to 
+         exit)</default>
+<contextlist><context>server config</context></contextlist>
+<modulelist><module>event</module><module>worker</module>
+<module>prefork</module>
+</modulelist>
+<compatibility>2.5.1 and later</compatibility>
+
+<usage>
+    <p>The <directive>AcceptErrorsNonFatal</directive> alters the servers
+    behavior under some rare errors that may occur while accepting a new 
+    client connection.  By default, the child process handling a request
+    will gracefully exit when nearly any socket error occurs during the
+    accept() system call.  This is to ensure a potentially unhealthy
+    child process does not try to take on more new connections.</p>
+
+    <p>With <directive>AcceptErrorsNonFatal</directive> set to "ON",
+    the process will <em>not</em> begin to exit if the accept() error is
+    ECONNREFUSED, ECONNABORTED, or ECONNRESET.</p>
+ 
+    <note>Some third-party firwewall software components may inject errors
+    into accept() processing, using return codes not specified by the 
+    operating system</note>
+</usage>
+</directivesynopsis>
+
 </modulesynopsis>

Modified: httpd/httpd/trunk/include/ap_listen.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/include/ap_listen.h?rev=1820098&r1=1820097&r2=1820098&view=diff
==============================================================================
--- httpd/httpd/trunk/include/ap_listen.h (original)
+++ httpd/httpd/trunk/include/ap_listen.h Thu Jan  4 15:10:45 2018
@@ -71,6 +71,12 @@ struct ap_listen_rec {
     const char* protocol;
 
     ap_slave_t *slave;
+
+    /**
+     * Allow the accept_func to return a wider set of return codes
+     */
+    int use_specific_errors;
+
 };
 
 /**
@@ -79,6 +85,9 @@ struct ap_listen_rec {
 AP_DECLARE_DATA extern ap_listen_rec *ap_listeners;
 AP_DECLARE_DATA extern int ap_num_listen_buckets;
 AP_DECLARE_DATA extern int ap_have_so_reuseport;
+AP_DECLARE_DATA extern int ap_accept_errors_nonfatal;
+
+AP_DECLARE(int) ap_accept_error_is_nonfatal(apr_status_t rv);
 
 /**
  * Setup all of the defaults for the listener list
@@ -143,6 +152,10 @@ AP_DECLARE_NONSTD(const char *) ap_set_r
                                                            void *dummy,
                                                            const char *arg);
 
+AP_DECLARE_NONSTD(const char *) ap_set_accept_errors_nonfatal(cmd_parms *cmd,
+                                                           void *dummy,
+                                                           int flag);
+
 #define LISTEN_COMMANDS \
 AP_INIT_TAKE1("ListenBacklog", ap_set_listenbacklog, NULL, RSRC_CONF, \
   "Maximum length of the queue of pending connections, as used by listen(2)"), \
@@ -153,8 +166,9 @@ AP_INIT_TAKE_ARGV("Listen", ap_set_liste
 AP_INIT_TAKE1("SendBufferSize", ap_set_send_buffer_size, NULL, RSRC_CONF, \
   "Send buffer size in bytes"), \
 AP_INIT_TAKE1("ReceiveBufferSize", ap_set_receive_buffer_size, NULL, \
-              RSRC_CONF, "Receive buffer size in bytes")
-
+              RSRC_CONF, "Receive buffer size in bytes"), \
+AP_INIT_FLAG("AcceptErrorsNonFatal", ap_set_accept_errors_nonfatal, NULL, \
+              RSRC_CONF, "Some accept() errors are not fatal to the process")
 #ifdef __cplusplus
 }
 #endif

Modified: httpd/httpd/trunk/os/unix/unixd.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/os/unix/unixd.c?rev=1820098&r1=1820097&r2=1820098&view=diff
==============================================================================
--- httpd/httpd/trunk/os/unix/unixd.c (original)
+++ httpd/httpd/trunk/os/unix/unixd.c Thu Jan  4 15:10:45 2018
@@ -320,6 +320,12 @@ AP_DECLARE(apr_status_t) ap_unixd_accept
     if (APR_STATUS_IS_EINTR(status)) {
         return status;
     }
+  
+    /* Let the caller handle slightly more varied return values */
+    if (lr->use_specific_errors && ap_accept_error_is_nonfatal(status)) { 
+        return status;
+    }
+
     /* Our old behaviour here was to continue after accept()
      * errors.  But this leads us into lots of troubles
      * because most of the errors are quite fatal.  For

Modified: httpd/httpd/trunk/server/listen.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/listen.c?rev=1820098&r1=1820097&r2=1820098&view=diff
==============================================================================
--- httpd/httpd/trunk/server/listen.c (original)
+++ httpd/httpd/trunk/server/listen.c Thu Jan  4 15:10:45 2018
@@ -59,6 +59,9 @@ static ap_listen_rec **ap_listen_buckets
  */
 AP_DECLARE_DATA int ap_have_so_reuseport = -1;
 
+/* Whether some accept() errors are non-fatal to the process */
+AP_DECLARE_DATA int ap_accept_errors_nonfatal = 0;
+
 static ap_listen_rec *old_listeners;
 static int ap_listenbacklog;
 static int ap_listencbratio;
@@ -793,6 +796,7 @@ AP_DECLARE(int) ap_setup_listeners(serve
     }
 
     for (lr = ap_listeners; lr; lr = lr->next) {
+        lr->use_specific_errors = ap_accept_errors_nonfatal;
         num_listeners++;
         found = 0;
         for (ls = s; ls && !found; ls = ls->next) {
@@ -1004,6 +1008,14 @@ AP_DECLARE(void) ap_listen_pre_config(vo
     }
 }
 
+AP_DECLARE(int) ap_accept_error_is_nonfatal(apr_status_t status)
+{
+
+   return APR_STATUS_IS_ECONNREFUSED(status)
+             || APR_STATUS_IS_ECONNABORTED(status)
+             || APR_STATUS_IS_ECONNRESET(status);
+}
+
 AP_DECLARE_NONSTD(const char *) ap_set_listener(cmd_parms *cmd, void *dummy,
                                                 int argc, char *const argv[])
 {
@@ -1128,6 +1140,14 @@ AP_DECLARE_NONSTD(const char *) ap_set_s
     return NULL;
 }
 
+AP_DECLARE_NONSTD(const char *) ap_set_accept_errors_nonfatal(cmd_parms *cmd,
+                                                           void *dummy,
+                                                           int flag)
+{
+   ap_accept_errors_nonfatal = flag;
+   return NULL;
+}
+
 AP_DECLARE_NONSTD(const char *) ap_set_receive_buffer_size(cmd_parms *cmd,
                                                            void *dummy,
                                                            const char *arg)

Modified: httpd/httpd/trunk/server/mpm/event/event.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/mpm/event/event.c?rev=1820098&r1=1820097&r2=1820098&view=diff
==============================================================================
--- httpd/httpd/trunk/server/mpm/event/event.c (original)
+++ httpd/httpd/trunk/server/mpm/event/event.c Thu Jan  4 15:10:45 2018
@@ -2068,6 +2068,10 @@ static void * APR_THREAD_FUNC listener_t
                         resource_shortage = 1;
                         signal_threads(ST_GRACEFUL);
                     }
+                    else if (ap_accept_error_is_nonfatal(rc)) { 
+                        ap_log_error(APLOG_MARK, APLOG_DEBUG, rc, ap_server_conf, 
+                                     "accept() on client socket failed");
+                    }
 
                     if (csd != NULL) {
                         conns_this_child--;

Modified: httpd/httpd/trunk/server/mpm/motorz/motorz.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/mpm/motorz/motorz.c?rev=1820098&r1=1820097&r2=1820098&view=diff
==============================================================================
--- httpd/httpd/trunk/server/mpm/motorz/motorz.c (original)
+++ httpd/httpd/trunk/server/mpm/motorz/motorz.c Thu Jan  4 15:10:45 2018
@@ -202,6 +202,11 @@ static apr_status_t motorz_io_accept(mot
                      "motorz_io_accept failed");
         clean_child_exit(APEXIT_CHILDSICK);
     }
+    else if (ap_accept_error_is_nonfatal(rv)) {
+        ap_log_error(APLOG_MARK, APLOG_DEBUG, rv, ap_server_conf,
+                "accept() on client socket failed");
+    }
+
     else {
         motorz_conn_t *scon = apr_pcalloc(ptrans, sizeof(motorz_conn_t));
         scon->pool = ptrans;

Modified: httpd/httpd/trunk/server/mpm/prefork/prefork.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/mpm/prefork/prefork.c?rev=1820098&r1=1820097&r2=1820098&view=diff
==============================================================================
--- httpd/httpd/trunk/server/mpm/prefork/prefork.c (original)
+++ httpd/httpd/trunk/server/mpm/prefork/prefork.c Thu Jan  4 15:10:45 2018
@@ -600,7 +600,12 @@ static void child_main(int child_num_arg
             /* resource shortage or should-not-occur occurred */
             clean_child_exit(APEXIT_CHILDSICK);
         }
-        else if (status != APR_SUCCESS) {
+        else if (ap_accept_error_is_nonfatal(rc)) {
+            ap_log_error(APLOG_MARK, APLOG_DEBUG, rc, ap_server_conf,
+                    "accept() on client socket failed");
+        }
+
+        if (status != APR_SUCCESS) {
             continue;
         }
 

Modified: httpd/httpd/trunk/server/mpm/worker/worker.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/mpm/worker/worker.c?rev=1820098&r1=1820097&r2=1820098&view=diff
==============================================================================
--- httpd/httpd/trunk/server/mpm/worker/worker.c (original)
+++ httpd/httpd/trunk/server/mpm/worker/worker.c Thu Jan  4 15:10:45 2018
@@ -699,6 +699,10 @@ static void * APR_THREAD_FUNC listener_t
                 resource_shortage = 1;
                 signal_threads(ST_GRACEFUL);
             }
+            else if (ap_accept_error_is_nonfatal(rv)) {
+                ap_log_error(APLOG_MARK, APLOG_DEBUG, rv, ap_server_conf,
+                        "accept() on client socket failed");
+            }
             if ((rv = SAFE_ACCEPT(apr_proc_mutex_unlock(my_bucket->mutex)))
                 != APR_SUCCESS) {
 



Re: svn commit: r1820098 - in /httpd/httpd/trunk: CHANGES docs/manual/mod/mpm_common.xml include/ap_listen.h os/unix/unixd.c server/listen.c server/mpm/event/event.c server/mpm/motorz/motorz.c server/mpm/prefork/prefork.c server/mpm/worker/worker.c

Posted by Eric Covener <co...@gmail.com>.
> Shouldn't we check that this is used GLOBAL_ONLY?
>
> ap_check_cmd_context(cmd, GLOBAL_ONLY);
>

>> Modified: httpd/httpd/trunk/server/mpm/prefork/prefork.c
>> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/mpm/prefork/prefork.c?rev=1820098&r1=1820097&r2=1820098&view=diff
>> ==============================================================================
>> --- httpd/httpd/trunk/server/mpm/prefork/prefork.c (original)
>> +++ httpd/httpd/trunk/server/mpm/prefork/prefork.c Thu Jan  4 15:10:45 2018
>> @@ -600,7 +600,12 @@ static void child_main(int child_num_arg
>>              /* resource shortage or should-not-occur occurred */
>>              clean_child_exit(APEXIT_CHILDSICK);
>>          }
>> -        else if (status != APR_SUCCESS) {
>> +        else if (ap_accept_error_is_nonfatal(rc)) {
>
> I guess else if is not needed and if is sufficient as clean_child_exit never returns.
>
>> +            ap_log_error(APLOG_MARK, APLOG_DEBUG, rc, ap_server_conf,
>
> I guess status should be used instead of rc in the two lines above.


Thanks! 1820113.

Re: svn commit: r1820098 - in /httpd/httpd/trunk: CHANGES docs/manual/mod/mpm_common.xml include/ap_listen.h os/unix/unixd.c server/listen.c server/mpm/event/event.c server/mpm/motorz/motorz.c server/mpm/prefork/prefork.c server/mpm/worker/worker.c

Posted by Ruediger Pluem <rp...@apache.org>.

On 01/04/2018 04:10 PM, covener@apache.org wrote:
> Author: covener
> Date: Thu Jan  4 15:10:45 2018
> New Revision: 1820098
> 
> URL: http://svn.apache.org/viewvc?rev=1820098&view=rev
> Log:
> Add "AcceptErrorsNonFatal" directive
> 
> This tweaks accept() failure processing by having ap_unixd_accept
> pass more errors up, and having the MPM's check against a macro
> to see if they are in a whitelist of non ENETDOWN/EMFILE kind 
> of potential process-wide errors.
> 
> Default behavior is still to exit.
> 
> 
> Modified:
>     httpd/httpd/trunk/CHANGES
>     httpd/httpd/trunk/docs/manual/mod/mpm_common.xml
>     httpd/httpd/trunk/include/ap_listen.h
>     httpd/httpd/trunk/os/unix/unixd.c
>     httpd/httpd/trunk/server/listen.c
>     httpd/httpd/trunk/server/mpm/event/event.c
>     httpd/httpd/trunk/server/mpm/motorz/motorz.c
>     httpd/httpd/trunk/server/mpm/prefork/prefork.c
>     httpd/httpd/trunk/server/mpm/worker/worker.c
> 

> Modified: httpd/httpd/trunk/server/listen.c
> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/listen.c?rev=1820098&r1=1820097&r2=1820098&view=diff
> ==============================================================================
> --- httpd/httpd/trunk/server/listen.c (original)
> +++ httpd/httpd/trunk/server/listen.c Thu Jan  4 15:10:45 2018

> @@ -1128,6 +1140,14 @@ AP_DECLARE_NONSTD(const char *) ap_set_s
>      return NULL;
>  }
>  
> +AP_DECLARE_NONSTD(const char *) ap_set_accept_errors_nonfatal(cmd_parms *cmd,
> +                                                           void *dummy,
> +                                                           int flag)
> +{
> +   ap_accept_errors_nonfatal = flag;
> +   return NULL;

Shouldn't we check that this is used GLOBAL_ONLY?

ap_check_cmd_context(cmd, GLOBAL_ONLY);


> +}
> +
>  AP_DECLARE_NONSTD(const char *) ap_set_receive_buffer_size(cmd_parms *cmd,
>                                                             void *dummy,
>                                                             const char *arg)
> 

> Modified: httpd/httpd/trunk/server/mpm/prefork/prefork.c
> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/mpm/prefork/prefork.c?rev=1820098&r1=1820097&r2=1820098&view=diff
> ==============================================================================
> --- httpd/httpd/trunk/server/mpm/prefork/prefork.c (original)
> +++ httpd/httpd/trunk/server/mpm/prefork/prefork.c Thu Jan  4 15:10:45 2018
> @@ -600,7 +600,12 @@ static void child_main(int child_num_arg
>              /* resource shortage or should-not-occur occurred */
>              clean_child_exit(APEXIT_CHILDSICK);
>          }
> -        else if (status != APR_SUCCESS) {
> +        else if (ap_accept_error_is_nonfatal(rc)) {

I guess else if is not needed and if is sufficient as clean_child_exit never returns.

> +            ap_log_error(APLOG_MARK, APLOG_DEBUG, rc, ap_server_conf,

I guess status should be used instead of rc in the two lines above.

> +                    "accept() on client socket failed");
> +        }
> +
> +        if (status != APR_SUCCESS) {
>              continue;
>          }
>  
> 

Regards

RĂ¼diger