Dynamic-server does not shut down after 30 seconds of inactivity

Gregor Rébel <[email protected]>
Newsgroups gmane.comp.web.fastcgi.devel
Message-ID <[email protected]>
Hi,

I'm writing a webengine that runs as a dynamic server via mod_fastcgi.
After some 30 seconds of inactivity this server should shutdown itself and save all unsaved session-data
back to disk. But instead of shutting down after receiving the signal, the script stays running and shuts
down when receiving the next http-request.

I have written a small watchdog which runs as a parallel thread and should send an ALRM-signal after 30 seconds.
This is what it looks like (simplified):

---------------------------------------------------------------------------------
my $WatchDog = threads->new(\&runWatchDog);
$SIG{ALRM} = sub { die("Alarm!\n"); };

eval
{
  while ( $self->{KeepServerRunning} && ($self->{CGI} = new CGI::Fast) )
  {
    .. compile page ..
  }
};
if ($@) { $FH_LOGFILE->print("main-event-loop interrupted: '$@'\n"); }

.. save session-data back to disk ..
exit 0;

sub runWatchDog #/
{
  sleep 30;
  $FH_LOGFILE->print("timer expired!\n");
  kill ALRM => $$;
} #/runWatchDog()
---------------------------------------------------------------------------------

This is what's in the logfiles:

Mon Dec  6 18:09:55 2004 - .log.QuickerPage:------------------------------------
timer expired!
--------------------------------------------------------------------------------

Nothing else happens.
A "ps -Af | grep wwwrun | grep perl | grep -v grep" shows that the script is still running:

  wwwrun 7431 7283 12 18:09 ? 00:00:26 /usr/bin/perl -I ./subpages -I ./modules -I ./cgi-modules -I ./modules/Plugins /srv/www/fcgi-bin/quickerpage.pl

But look what happens on the next http-request:

Mon Dec  6 18:10:28 2004 - .log.QuickerPage:------------------------------------
main-event-loop interrupted: 'Alarm!
'
--------------------------------------------------------------------------------

The webserver returns an error-page (Error 500 - internal error) and the script terminates.

This behaviour is very bad, because it means that this request is not being served.
Any subsequent http-request will cause mod_fastcgi to restart the script and to serve requests again.


What's wrong with my script?
May I give arguments to CGI::Fast->new() to make it work?

Funny thing:
If I remove '$SIG{ALRM} = sub { die("Alarm!\n"); };' from my script, then
the script will instantly terminate after the watchdog has expired.

Mon Dec  6 18:33:43 2004 - .log.QuickerPage:------------------------------------
timer expired!
--------------------------------------------------------------------------------

Mon Dec  6 18:33:43 2004 - /var/log/apache2/error_log:--------------------------
[Mon Dec 06 18:33:37 2004] [warn] FastCGI: (dynamic) server "/srv/www/htdocs/quickerpage.homelinux.net/fcgi-bin/quickerpage.pl" (pid 7925) terminated due to uncaught signal '14' (Alarm clock)
--------------------------------------------------------------------------------

But now, no data could be saved! :-(



This is my playground: ---------------------------------------------------------

SuSE Linux 9.2 (Linux iqx 2.6.8-24-default #1 Wed Oct 6 09:16:23 UTC 2004 i686 athlon i386 GNU/Linux)

Server version: Apache/2.0.52
Server built:   Dec  6 2004 02:46:27
Server's Module Magic Number: 20020903:9
Architecture:   32-bit
Server compiled with....
 -D APACHE_MPM_DIR="server/mpm/prefork"
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D HTTPD_ROOT="/usr/share/apache2"
 -D SUEXEC_BIN="/usr/sbin/suexec2"
 -D DEFAULT_PIDLOG="/var/run/httpd2.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_LOCKFILE="/var/run/accept.lock"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="/etc/apache2/mime.types"
 -D SERVER_CONFIG_FILE="/etc/apache2/httpd.conf"

mod_fastcgi-SNAP-0404142202

This line configures my dynamic servers:

  FastCgiConfig -maxClassProcesses 1 -singleThreshold 1 -appConnTimeout 120 -idle-timeout 60

  
perl v5.8.5
  Compile-time options: MULTIPLICITY USE_ITHREADS USE_LARGE_FILES PERL_IMPLICIT_CONTEXT
  Built under linux
  Compiled at Oct  1 2004 23:30:38
  @INC:
    /usr/lib/perl5/5.8.5/i586-linux-thread-multi
    /usr/lib/perl5/5.8.5
    /usr/lib/perl5/site_perl/5.8.5/i586-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.5
    /usr/lib/perl5/site_perl
    /usr/lib/perl5/vendor_perl/5.8.5/i586-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.5
    /usr/lib/perl5/vendor_perl
--------------------------------------------------------------------------------

Any help would be appreciated


in tippo ergo..

___________________________________
fastcgi-developers mailing list
http://fastcgi.com/fastcgi-developers/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.