You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Dirk-Willem van Gulik <di...@elect6.jrc.it> on 1997/11/26 16:59:18 UTC

fundamentally wrong forking prior to garbage collection in proxy/

Forking off the garbage collecting child in the proxy.

Anything fundamentally wrong with this quick and dirty hack, it
does seem to work and my my employer happy. But it seems to
crude to me.

Dw.

diff -c3 -r apache_1.2.4/src/modules/proxy/proxy_cache.c
apache_1.2.4-work/src/modules/proxy/proxy_cache.c
*** apache_1.2.4/src/modules/proxy/proxy_cache.c        Fri Aug 15
19:08:55 1997
--- apache_1.2.4-work/src/modules/proxy/proxy_cache.c   Wed Nov 26
16:48:07 1997
***************
*** 88,94 ****
  static int sub_garbage_coll(request_rec *r,array_header *files,
                            const char *cachedir,const char *cachesubdir);
  
! void proxy_garbage_coll(request_rec *r)
      {
      const char *cachedir;
      void *sconf = r->server->module_config;
--- 88,112 ----
  static int sub_garbage_coll(request_rec *r,array_header *files,
                            const char *cachedir,const char *cachesubdir);
  
! void _proxy_garbage_coll(request_rec *r);
! 
! void proxy_garbage_coll(request_rec *r) {
! 
!     pid_t chld = fork();
!  
!     /* parent return.. */
!     if ( chld > 0 )
!       return;
!     
!     _proxy_garbage_coll(r);
! 
!     if (chld == 0) /* only true children exit */
!       exit(0);
! 
!     return; /* but return if we did not fork OK */
! 
! }
! 
! void _proxy_garbage_coll(request_rec *r)
      {
      const char *cachedir;
      void *sconf = r->server->module_config;
***************
*** 101,106 ****
--- 119,129 ----
      int i, timefd;
      static time_t lastcheck=BAD_DATE;  /* static data!!! */
  
+     pid_t chld = fork();
+ 
+     if (chld > 0) 
+       return;
+    
      cachedir = conf->root;
      cachesize = conf->space;
      every = conf->gcinterval;


http://cils.ceo.org                         http://enrm.ceo.org
dirkx@technologist.com                     Dirk.vanGulik@jrc.it
+39 332 78 0014       +39 332 78 9549       fax +39 332 78 9185
ISEI/ESBA;                     The Center For Earth Observation
Joint Research Centre of the European Communities, Ispra, Italy


Re: fundamentally wrong forking prior to garbage collection in proxy/

Posted by Martin Kraemer <Ma...@mch.sni.de>.
On Wed, Nov 26, 1997 at 04:59:18PM +0100, Dirk-Willem van Gulik wrote:
> 
> Forking off the garbage collecting child in the proxy.

Good idea. But is it absolutely sure that another request cannot cause
another garbage collection to fork off, e.g., when the disk is full
and GC has to be done before the next interval? (Locking?)

    Martin
-- 
| S I E M E N S |  <Ma...@mch.sni.de>  |      Siemens Nixdorf
| ------------- |   Voice: +49-89-636-46021     |  Informationssysteme AG
| N I X D O R F |   FAX:   +49-89-636-44994     |   81730 Munich, Germany
~~~~~~~~~~~~~~~~My opinions only, of course; pgp key available on request

Re: fundamentally wrong forking prior to garbage collection in proxy/

Posted by Ben Laurie <be...@algroup.co.uk>.
Dean Gaudet wrote:
> 
> I haven't looked to see... but you should fork() twice to disassociate
> yourself from the child, and the child should wait for the first fork()ed
> process to return before continuing (otherwise there'll be a zombie).  The
> whole thing should be inside a block_alarms() and unblock_alarms()
> section.  And it's probably not something we can do under win32...

You can do it in a thread under Win32, I guess. Cleanup could get a
little complex, though.

Cheers,

Ben.

-- 
Ben Laurie            |Phone: +44 (181) 735 0686|Apache Group member
Freelance Consultant  |Fax:   +44 (181) 735 0689|http://www.apache.org
and Technical Director|Email: ben@algroup.co.uk |Apache-SSL author
A.L. Digital Ltd,     |http://www.algroup.co.uk/Apache-SSL
London, England.      |"Apache: TDG" http://www.ora.com/catalog/apache

Re: fundamentally wrong forking prior to garbage collection in proxy/

Posted by Dean Gaudet <dg...@arctic.org>.
I haven't looked to see... but you should fork() twice to disassociate
yourself from the child, and the child should wait for the first fork()ed
process to return before continuing (otherwise there'll be a zombie).  The
whole thing should be inside a block_alarms() and unblock_alarms()
section.  And it's probably not something we can do under win32...

You may even want to setpgrp() after the second fork so that the httpd
parent can't send you SIGHUP/USR1/TERM. 

Dean

On Wed, 26 Nov 1997, Dirk-Willem van Gulik wrote:

> 
> Forking off the garbage collecting child in the proxy.
> 
> Anything fundamentally wrong with this quick and dirty hack, it
> does seem to work and my my employer happy. But it seems to
> crude to me.
> 
> Dw.
> 
> diff -c3 -r apache_1.2.4/src/modules/proxy/proxy_cache.c
> apache_1.2.4-work/src/modules/proxy/proxy_cache.c
> *** apache_1.2.4/src/modules/proxy/proxy_cache.c        Fri Aug 15
> 19:08:55 1997
> --- apache_1.2.4-work/src/modules/proxy/proxy_cache.c   Wed Nov 26
> 16:48:07 1997
> ***************
> *** 88,94 ****
>   static int sub_garbage_coll(request_rec *r,array_header *files,
>                             const char *cachedir,const char *cachesubdir);
>   
> ! void proxy_garbage_coll(request_rec *r)
>       {
>       const char *cachedir;
>       void *sconf = r->server->module_config;
> --- 88,112 ----
>   static int sub_garbage_coll(request_rec *r,array_header *files,
>                             const char *cachedir,const char *cachesubdir);
>   
> ! void _proxy_garbage_coll(request_rec *r);
> ! 
> ! void proxy_garbage_coll(request_rec *r) {
> ! 
> !     pid_t chld = fork();
> !  
> !     /* parent return.. */
> !     if ( chld > 0 )
> !       return;
> !     
> !     _proxy_garbage_coll(r);
> ! 
> !     if (chld == 0) /* only true children exit */
> !       exit(0);
> ! 
> !     return; /* but return if we did not fork OK */
> ! 
> ! }
> ! 
> ! void _proxy_garbage_coll(request_rec *r)
>       {
>       const char *cachedir;
>       void *sconf = r->server->module_config;
> ***************
> *** 101,106 ****
> --- 119,129 ----
>       int i, timefd;
>       static time_t lastcheck=BAD_DATE;  /* static data!!! */
>   
> +     pid_t chld = fork();
> + 
> +     if (chld > 0) 
> +       return;
> +    
>       cachedir = conf->root;
>       cachesize = conf->space;
>       every = conf->gcinterval;
> 
> 
> http://cils.ceo.org                         http://enrm.ceo.org
> dirkx@technologist.com                     Dirk.vanGulik@jrc.it
> +39 332 78 0014       +39 332 78 9549       fax +39 332 78 9185
> ISEI/ESBA;                     The Center For Earth Observation
> Joint Research Centre of the European Communities, Ispra, Italy
> 
>