hang with mysql in execute

From: Chris Masters (rotis23_at_yahoo.com)
Date: 03/19/05

  • Next message: Richard Rice: "Error installing DBD::DB2 on AIX 5"
    Date: Sat, 19 Mar 2005 09:37:05 -0800 (PST)
    To: dbi-users@perl.org
    
    

    Hi All,

    A firewall is terminating my connection with a mysql
    database after a period of inactivity. I've used the
    following code (with ref to cpan docs and connect) and
    it still causes a hang.

    ###################################################

    my $result = 0;
    my $alarm = 0;
    eval
    {
        #set alarm to timeout query hangs
        my $h = Sys::SigAction::set_sig_handler( 'ALRM'
    ,sub { $alarm = 1; } );
        alarm(2);

        my $sth = $dbh->prepare("SELECT 1");
        $sth->execute();
        $result = 1;

        alarm(0);
    };

    alarm(0);

    if($@ || $alarm)
    {
        syslog('err',"execute error: $@");
        $result = 0;
    }

    return $result;

    ###############################################

    Am I using alarms wrongly with perl?

    Would it be better to use a select(2) wrapper?

    Any other ideas to prevent this hang?

    Thanks for any help on this.

    Chris

    redhat 8.0
    perl-5.8.0-88.3
    perl-DBI-1.30-1
    perl-DBD-MySQL-2.1017-3

                    
    __________________________________
    Do you Yahoo!?
    Yahoo! Small Business - Try our new resources site!
    http://smallbusiness.yahoo.com/resources/


  • Next message: Richard Rice: "Error installing DBD::DB2 on AIX 5"

    Relevant Pages

    • SUMMARY: Avoiding NFS clients Hang when NFS server dies
      ... > of disks served on other tru64 hosts and Linux. ... including df) hang as well. ... > Do you Yahoo!? ... easy-to-use web site design software ...
      (Tru64-UNIX-Managers)
    • Re: hang with mysql in execute
      ... Thanks, Chris ... > it still causes a hang. ... > #set alarm to timeout query hangs ... > Do you Yahoo!? ...
      (perl.dbi.users)
    • Re: DIY Wireless System Recommendations?
      ... buzzes, it will hang up, and dial again and again and again, until it ... NO you won't know if it's an alarm condition or a low battery or your wife ...
      (alt.security.alarms)
    • Re: sntp hangs if network not available
      ... >setting up alarm for 3 secs ... >Before recvfrom ... Skip the bars and set-ups and start using Yahoo! ... Personals for free ...
      (comp.protocols.time.ntp)
    • Re: On those Elevated MRT platform stations
      ... the family will be charged maximum by MRT? ... > They should hang up a permanent sign board display: ... > Do You Yahoo!? ... Mail has the best spam protection around ...
      (soc.culture.singapore)