enemyofthestate has asked for the wisdom of the Perl Monks concerning the following question:

Never mind! I finally figured out that Apache sends a SIGTERM...

How does a Fast CGI program know that Apache is terminating it? AFAIK the basic process for Fast CGI is:

## Initialize stuff while (my $cgi = Fast::CGI->new) { # do something undef $cgi; } ## cleanup stuff
It is how to run the cleanup part that I cannot figure out. I tried a few tests (mostly just printing something to STDERR) and it looks like when Apache terminates the program the cleanup code never gets executed. So far there have been no problems attributable to the above but the code interfaces to a vendor supplied C library and, without being able to tell it to clean up after itself, I don't know what kind of junk it might leave laying about. I'd like to be clear on this before going to production.

Replies are listed 'Best First'.
Re: Fast CGI termination
by ikegami (Patriarch) on Sep 15, 2017 at 04:08 UTC

    How does a Fast CGI program know that Apache is terminating it?

    That question makes no sense. Apache doesn't terminate the FCGI daemon.

    It is how to run the cleanup part that I cannot figure out?

    In theory, you should never reach that code. `CGI::Fast->new` will only fail if there's a bug in the library or for OS errors such as accept failing.