6

I have a Perl Dancer web application which uses the mod_fastcgi serving method from Apache2. The application has to accept uploaded files. When a user is uploading a file and presses the stop button, the fastcgi process hangs, running at 100% until I manually kill the process.

Is there any setting that can automatically kill a process that has hung like this? Is there any way to automatically kill a fastcgi process that has been running for a certain amount of time?

mbergins
  • 61
  • 4
  • 1
    I think you need to understand why it gets stuck in 100% first, if it is mod_fastcgi's fault or your code. If it is your code, see where it gets stuck, if it is mod_fastcgi's fault, open a bug in their site – Noam Rathaus Nov 26 '13 at 15:59

2 Answers2

2

No, it is not supported by mod_fastcgi.

That said, you have several alternatives:

  • Wrap your perl code in a timeout-based module, such as Time::Out.
  • use ulimit -t to have the kernel kill the runaway process once his CPU quota is over.

The second solution will be somewhat difficult to implement, since you don't want to kill the whole apache process. It is explained more in detail in an Unix StackExchange question.

Community
  • 1
  • 1
Steve Schnepp
  • 4,620
  • 5
  • 39
  • 54
  • I hadn't heard of the Time::Out module and I tested it around the portion of my code that handles the upload process. Looks like the "upload" dancer function isn't the portion that is hanging, so it must be something else. – mbergins Dec 08 '13 at 18:12
0

Since the function I'm interested in isn't an option with mod_fastcgi and I can't seem to find the portion of the code to wrap in Time::Out to kill the process. I thought I would share my hacked ttogether solution.

I searched for a single linux command to do this, but killall didn't work (it wouldn't specifically find just the perl command running that server instance) and pkill didn't either (couldn't specify an age of the process to kill).

So I wrote a short perl script, which is run as root, to kill jobs with the correct name and age of dancer mod_fastcgi server instances:

#!/usr/bin/perl -w

use Proc::ProcessTable;

$t = new Proc::ProcessTable( 'cache_ttys' => 1 );  

foreach $p ( @{$t->table} ){
    if ($p->cmndline =~ /perl.*dispatch.fcgi/) {
        my $run_time_min = $p->time/(1000000*60);
        if ($run_time_min >= 15) {
            # print "Found this job to kill: ". $p->pid . $p->cmndline."\n". $run_time_min . "\n";
            kill 'KILL', $p->pid;
        }   
    }   
}
mbergins
  • 61
  • 4