I am programming a server daemon that pre-forks "worker" children to do time consuming work, and pre-forks a "reporting" child to handle sending reports from the "workers" back to the database.
I have a 60 second alarm signal inside of an eval{} statement that encloses the mysql database work. No database work should take longer than a few seconds. After a day or two uptime, the "reporting" child hangs for 1 - 4 hours where nothing takes place and then dies because of the alarm signal. The eval{} statement is unable to trap the die(). Here is my code:
my $dbh;
RECONNECT:
eval {
my $dsn = "DBI:$driver:database=$database;host=$hostname;mysql_con
+nect_timeout=10";
$dbh = DBI->connect($dsn, $username, $password, { RaiseError => 1,
+ PrintError => 0, AutoCommit => 1 });
};
if( $@ ) {
goto RECONNECT;
}
eval {
# Setup ALRM handler signal
local $SIG{ALRM} = sub { die "timeout\n" };
alarm( 60 );
$dbh->do("INSERT INTO table_name VALUES ( data, ... )");
alarm( 0 );
};
if( $@ ) {
if( $@ =~ /timeout/ ) {
print "Timed out\n";
} else {
alarm( 0 );
}
}
How would you go about setting up a foolproof daemon with a constant mysql server connection?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.