set a limit on how long a Clark Kent query can run
authorGalen Charlton <gmc@esilibrary.com>
Fri, 20 Mar 2015 20:55:22 +0000 (20:55 +0000)
committerGalen Charlton <gmc@esilibrary.com>
Fri, 20 Mar 2015 20:55:22 +0000 (20:55 +0000)
Reporter queries that take too long to run are very often
simply malformed, and in extreme cases can chew through
a lot of temp disk space on PostgreSQL servers.  To avoid
this, Clark Kent by defaults only allows a query to run
for up to 10 minutes by setting a local statement timeout.

The value of the timeout can be tweaked by setting the a
new command-line option for clark-kent.pl, --statement-timeout.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Open-ILS/src/reporter/clark-kent.pl

index f2e4056..3821011 100755 (executable)
@@ -34,12 +34,14 @@ my ($count, $config, $sleep_interval, $lockfile, $daemon) = (1, 'SYSCONFDIR/open
 # set upper bound on number of rows in the resultset
 # before Clark refuses to try to draw a chart
 my $max_rows_for_charts = 1000;
+my $statement_timeout = 10 * 60 * 1000;
 
 GetOptions(
        "daemon"        => \$daemon,
        "sleep=i"       => \$sleep_interval,
        "concurrency=i" => \$count,
        "max-rows-for-charts=i" => \$max_rows_for_charts,
+       "statement-timeout=i" => \$statement_timeout,
        "bootstrap|boostrap=s"  => \$config,
        "lockfile=s"    => \$lockfile,
 );
@@ -208,6 +210,7 @@ for my $r ( @reports ) {
                  RaiseError => 1
                }
        );
+       $data_dbh->do('SET statement_timeout = ?', {}, $statement_timeout);
 
        try {
                $state_dbh->do(<<'              SQL',{}, $r->{id});