Hi Henri,

Henri Asseily wrote:
> From DBIx::HA (fudged a bit):

Thanks for the info; I changed my function to loosely match, but it
still fails to actually die and immediately return from the eval{} block.

Here's the function now:

 # Create database connection
 my($dbh);
 my($alarm) = 30;
 eval {
  no strict;
  my $h = set_sig_handler('ALRM', sub {die "timeout";}, {mask=>['ALRM'],
safe=>1});
  alarm($alarm);
  $dbh = MailWatchCommon::db_connect();
  alarm(0);
 };
 alarm(0);
 if($@) {
  MailScanner::Log::WarnLog("MailWatch Error: Unable to initialise
database connection: %s", $@);
  DisableMailWatchLogging();
  return undef;
 }

MailWatchCommon::db_connect does this:

# Database
use DBI;
use DBD::Pg qw(:pg_types);

sub db_connect {
 # Use first argument as cache key
 my($cachekey) = (@_) ? shift : 'DEFAULT';
 my($dsn) =
"DBI:Pg:dbname=".$cfg{'database.name'}.";host=".$cfg{'database.host'};
 my($dbh);
 $dbh = DBI->connect_cached($dsn, $cfg{'database.user'},
$cfg{'database.password'}, { RaiseError => 1, InactiveDestroy => 1,
AutoCommit => 1, ShowErrorStatement => 1, private_mailwatch_cachekey =>
$cachekey });
 return $dbh;
}

Here's the strace:

rt_sigprocmask(SIG_BLOCK, ~[RTMIN RT_1], [], 8) = 0
rt_sigaction(SIGALRM, NULL, {SIG_DFL}, 8) = 0
rt_sigprocmask(SIG_BLOCK, [ALRM], ~[KILL STOP RTMIN RT_1], 8) = 0
rt_sigaction(SIGALRM, {0xd30835, [], SA_RESTORER, 0xc29a98}, {SIG_DFL},
8) = 0
rt_sigprocmask(SIG_SETMASK, ~[KILL STOP RTMIN RT_1], NULL, 8) = 0
rt_sigaction(SIGALRM, {0xd30835, [ALRM], SA_RESTORER, 0xc29a98}, NULL,
8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
alarm(30)                               = 0
rt_sigaction(SIGPIPE, {SIG_IGN}, {SIG_DFL}, 8) = 0
send(9, "Q\0\0\0\37SELECT \'DBD::Pg ping test\'\0", 32, 0) = 32
rt_sigaction(SIGPIPE, {SIG_DFL}, {SIG_IGN}, 8) = 0
poll([{fd=9, events=POLLIN|POLLERR}], 1, -1) = -1 EINTR (Interrupted
system call)
--- SIGALRM (Alarm clock) @ 0 (0) ---
sigreturn()                             = ? (mask now [])
poll(

This is running on Linux 2.6.9, Perl 5.8.8, DBI 1.607 and DBD::Pg 2.10.7

Kind regards,
Steve.

Reply via email to