httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dean Gaudet <dgau...@arctic.org>
Subject Re: [PATCH] fix for server hanging on HUP
Date Tue, 11 Feb 1997 07:37:13 GMT
I think I'd rather if you did this:

    for( tries = 0; tries < 4; ++tries ) {
	for( i = 0; i < HARD_SERVER_LIMIT; ++i ) {
	    /* do the other gunk */
	}
	if( none left to wait for ) break;
	sleep(3);
    }

That way it tries each child pid once, then goes through and thwacks any
stragglers a bit harder, then goes through again a bit harder...

Otherwise you might end up in sleep(3) way too much for my tastes.  The
server isn't serving hits while it's doing all this sleeping.

Dean

On Mon, 10 Feb 1997, Marc Slemko wrote:

> Ok, today we learnt about loops.  My revised patch is below.  It
> works for me on a server running 1.1 (and appears to fix the problem),
> and appears to work fine in 1.2 as well.  Testers appreciated, both
> for those who have been having problems and those who haven't.
> 
> 
> Index: http_main.c
> ===================================================================
> RCS file: /export/home/cvs/apache/src/http_main.c,v
> retrieving revision 1.118
> diff -c -r1.118 http_main.c
> *** http_main.c	1997/02/10 21:22:20	1.118
> --- http_main.c	1997/02/11 02:28:32
> ***************
> *** 1017,1025 ****
>       sync_scoreboard_image();
>       for (i = 0; i < HARD_SERVER_LIMIT; ++i) {
>   	int pid = scoreboard_image->servers[i].pid;
>   
> ! 	if (pid != my_pid && pid != 0)
> ! 	    waitpid (scoreboard_image->servers[i].pid, &status, 0);
>       }
>   }
>   
> --- 1017,1067 ----
>       sync_scoreboard_image();
>       for (i = 0; i < HARD_SERVER_LIMIT; ++i) {
>   	int pid = scoreboard_image->servers[i].pid;
> + 	int tries = 0, waitret = 0;
>   
> ! 	if (pid != my_pid && pid != 0) {
> ! 	    /* sometimes it appears like the SIGHUP to the child gets lost.  
> ! 	     * To avoid hanging here waiting, we whack it if it hasn't 
> ! 	     * already exited.
> ! 	     */
> ! 	    while (waitret == 0 && tries <= 4) {
> ! 		waitret = waitpid(pid, &status, WNOHANG);
> ! 		if (waitret == 0) {	/* no status to report; hasn't exited */
> ! 		    switch (tries) {
> ! 		    case 0:
> ! 			/* first time through, we assume it is just slow */
> ! 			log_printf(server_conf, "child process %d did not exit (just slow?), will try again",
pid);
> ! 			break;
> ! 		    case 1:
> ! 			/* perhaps it missed the SIGHUP, lets try again */
> ! 			log_printf(server_conf, "child process %d did not exit, sending another SIGHUP",
pid);
> ! 			kill(pid, SIGHUP);
> ! 			break;
> ! 		    case 2:
> ! 			/* ok, now it is being annoying */
> ! 			log_printf(server_conf, "child process %d still did not exit, sending a SIGTERM",
pid);
> ! 			kill(pid, SIGTERM);
> ! 			break;
> ! 		    case 3:
> ! 			/* die child scum */
> ! 			log_printf(server_conf, "child process %d still did not exit, sending a SIGKILL",
pid);
> ! 			kill(pid, SIGKILL);
> ! 			break;
> ! 		    case 4:
> ! 			/* gave it our best shot, but alas...  If this really 
> ! 			 * is a child we are trying to kill and it really hasn't
> ! 			 * exited, we will likely fail to bind to the port
> ! 			 * after the restart.
> ! 			 */
> ! 			log_printf(server_conf, "could not make child process %d exit, attempting to continue
anyway", pid);
> ! 			continue;
> ! 			break;
> ! 		    }
> ! 		    tries++;
> ! 		    sleep(3);
> ! 		}
> ! 	    }
> ! 	}
>       }
>   }
>   
> 
> 
> 


Mime
View raw message