troubleshooting Question

Reliable Timeout for DBI and mysql

Avatar of Andr6w
Andr6w asked on
DatabasesPerlMySQL Server
3 Comments2 Solutions2211 ViewsLast Modified:
Hello Esteemed Code Friends

It's been a while since I try to set up a reliable timeout for our site's search engine. I've noticed that there's some issue with simple alarm calls not working because of "unsafe signals". So I heard that the solution is this DBIx::Timeout module.
http://search.cpan.org/~samtregar/DBIx-Timeout-1.01/lib/DBIx/Timeout.pm

But 2 problems:
1) It doesn't seem to trigger the alarm either
2) There's some caveat that worries me, described below. I'm running this on a mod_perl script, so this is problematic.

"If the child process wakes up it kills the parent's DB thread and  exits with a code so the parent knows it was timed out. NOTE: After this call your database connection may be killed even if no timeout occurred. This is due to a race condition - the child may wake up just as parent process finishes. Patches addressing this bug are welcome. Until this is fixed you should be ready to reconnect after call_with_timeout()."

Any better ideas?

Thanks

Andr6w




#########################
# Start of timeout #####
use DBIx::Timeout;
 
  # run code() for a maximum of 1 second, doing work with $dbh
  local our $ok = DBIx::Timeout->call_with_timeout(
    dbh     => $dbh,
    code    => sub { 
    
       $sth->execute( );
    
    },
    timeout => 1
  );
 
  # handle the result
  if (!$ok) {
    die "You ran out of time!";
  }
 
#########################
# End of timeout ########
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros