httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Trawick <traw...@attglobal.net>
Subject [PATCH] threaded.c and apr_thread_create() failures
Date Wed, 25 Jul 2001 16:27:13 GMT
exit(APEXIT_CHILDFATAL) isn't too cool... the parent process bails out
without cleaning stuff up

this patch retries apr_thread_create() after an interval; apache stays
healthy (though it doesn't free up system resources; it merely assumes
they will free up after a time) 

maybe we shouldn't retry the thread creation endlessly?

maybe we should sleep a different interval?

Index: server/mpm/threaded/threaded.c
===================================================================
RCS file: /home/cvspublic/httpd-2.0/server/mpm/threaded/threaded.c,v
retrieving revision 1.47
diff -u -r1.47 threaded.c
--- server/mpm/threaded/threaded.c	2001/07/24 05:19:47	1.47
+++ server/mpm/threaded/threaded.c	2001/07/25 16:29:44
@@ -705,24 +705,28 @@
   	    /* We are creating threads right now */
 	    (void) ap_update_child_status(my_child_num, i, SERVER_STARTING, 
 	  			          (request_rec *) NULL);
-	    /* We let each thread update it's own scoreboard entry.  This is 
-             * done because it let's us deal with tid better.
+            /* We let each thread update its own scoreboard entry.  This is
+             * done because it lets us deal with tid better.
 	     */
 	    if ((rv = apr_thread_create(&threads[i], thread_attr, worker_thread, my_info, pchild)))
{
+                /* thread creation didn't succeed. Fix the scoreboard or else
+                 * it will say SERVER_STARTING forever and ever
+                 */
+                (void) ap_update_child_status(my_child_num, i, SERVER_DEAD, 
+                                              (request_rec *) NULL);
+
 	        ap_log_error(APLOG_MARK, APLOG_ALERT, rv, ap_server_conf,
 			     "apr_thread_create: unable to create worker thread");
-                /* In case system resources are maxxed out, we don't want
-                   Apache running away with the CPU trying to fork over and
-                   over and over again if we exit. */
-                sleep(10);
-	        clean_child_exit(APEXIT_CHILDFATAL);
+                sleep(5);
 	    }
-            threads_created++;
+            else {
+                threads_created++;
+            }
         }
         if (workers_may_exit || threads_created == ap_threads_per_child) {
             break;
         }
-        sleep(1);
+        sleep(1); /* wait for previous generation to clean up an entry */
     }
     
     /* What state should this child_main process be listed as in the scoreboard...?
@@ -814,15 +818,13 @@
     ts->child_num_arg = child_num_arg;
     ts->threadattr = thread_attr;
 
-    if ((rv = apr_thread_create(&threads[i], thread_attr, start_threads, ts, pchild)))
{
-        ap_log_error(APLOG_MARK, APLOG_ALERT, rv, ap_server_conf,
-                     "apr_thread_create: unable to create worker thread");
-        /* In case system resources are maxxed out, we don't want
-           Apache running away with the CPU trying to fork over and
-           over and over again if we exit. */
-        sleep(10);
-        clean_child_exit(APEXIT_CHILDFATAL);
-    }
+    do {
+        if ((rv = apr_thread_create(&threads[i], thread_attr, start_threads, ts, pchild)))
{
+            ap_log_error(APLOG_MARK, APLOG_ALERT, rv, ap_server_conf,
+                         "apr_thread_create: unable to create worker thread");
+            sleep(5);
+        }
+    } while (rv != APR_SUCCESS);
 
     apr_signal_thread(check_signal);
 

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

Mime
View raw message