httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Trawick <trawi...@bellsouth.net>
Subject [PATCH] bringing down the server from an MPM thread
Date Tue, 25 Jul 2000 20:18:30 GMT
There doesn't seem to be any existing logic in the Unix mpm(s) to
bring down the server after a fatal error that is encountered in 
a worker thread.  For the moment, I'm concerned with errors from
ap_poll() and ap_accept().

Currently, after an error from ap_poll() in a worker thread, the
worker threads will go away and then the process will exit(0).  The
parent will then restart the process.  With this change, after a fatal
error is encountered in a worker thread, a flag
(fatal_error_in_worker) is set so that the process exits with status
APEXIT_CHILDFATAL.  This triggers the parent process to bring
everything down.

Any better ideas for how to do this?

The patch is just a proof of concept.  I need to pick up the right
accept() error classification from Apache 1.3 and also get the change
to help the DEXTER flavor of mpmt.c too.

Index: modules/mpm/mpmt/mpmt.c
===================================================================
RCS file: /cvs/apache/apache-2.0/src/modules/mpm/mpmt/mpmt.c,v
retrieving revision 1.18
diff -u -r1.18 mpmt.c
--- mpmt.c	2000/07/25 17:39:16	1.18
+++ mpmt.c	2000/07/25 20:15:40
@@ -125,6 +125,7 @@
 static int min_spare_threads = 0;
 static int max_spare_threads = 0;
 static int workers_may_exit = 0;
+static int fatal_error_in_worker = 0;
 static int requests_this_child;
 static int num_listensocks = 0;
 static ap_socket_t **listensocks;
@@ -818,6 +819,7 @@
                 ap_log_error(APLOG_MARK, APLOG_ERR, ret, (const server_rec *)
                              ap_server_conf, "ap_poll: (listen)");
                 workers_may_exit = 1;
+                fatal_error_in_worker = 1;
             }
 
             if (workers_may_exit) break;
@@ -857,6 +859,18 @@
             if ((rv = ap_accept(&csd, sd, ptrans)) != APR_SUCCESS) {
                 ap_log_error(APLOG_MARK, APLOG_ERR, rv, ap_server_conf, 
                              "ap_accept");
+                csd = NULL;
+                switch(rv)
+                {
+                /* TODO: From Apache 1.3, bring in the classification of 
+                 * various accept() errors.
+                 */
+                default:
+                    ap_log_error(APLOG_MARK, APLOG_EMERG, rv, ap_server_conf,
+                                 "ap_accept: giving up.");
+                    workers_may_exit = 1;
+                    fatal_error_in_worker = 1;
+                }
             }
             if ((rv = SAFE_ACCEPT(ap_unlock(process_accept_mutex)))
                 != APR_SUCCESS) {
@@ -868,7 +882,9 @@
 #ifndef PREFORK
             pthread_mutex_unlock(&thread_accept_mutex);
 #endif
-            process_socket(ptrans, csd, process_slot * HARD_THREAD_LIMIT + thread_slot);
+            if (csd) {
+                process_socket(ptrans, csd, process_slot * HARD_THREAD_LIMIT + thread_slot);
+            }
             requests_this_child--;
         }
         else {
@@ -1026,7 +1042,15 @@
     switch (signal_received) {
         case SIGTERM:
         case SIGINT:
-            just_die(signal_received);
+            if (fatal_error_in_worker) {
+                ap_log_error(APLOG_MARK, APLOG_ALERT | APLOG_NOERRNO, 0, 
+                             ap_server_conf,
+                             "A fatal error occured in a worker thread.");
+                exit(APEXIT_CHILDFATAL);
+            }
+            else {
+                just_die(signal_received);
+            }
             break;
         default:
             ap_log_error(APLOG_MARK, APLOG_ALERT, errno, ap_server_conf,


-- 
Jeff Trawick | trawick@ibm.net | PGP public key at web site:
     http://www.geocities.com/SiliconValley/Park/9289/
          Born in Roswell... married an alien...

Mime
View raw message