continue attempting to handle mysql hanging on queries, RT#10574
[freeside.git] / FS / bin / freeside-torrus-srvderive
index 95cc76d..61d5fe6 100644 (file)
@@ -94,31 +94,27 @@ MAIN: while (1) {
     warn $ssql if $DEBUG > 2;
     my $sth = dbh->prepare($ssql) or die $DBI::errstr; #better recovery here?
 
-    warn "executing search" if $DEBUG;
+    warn "executing search\n" if $DEBUG;
 
     eval {
-      my $timeout = set_sig_handler(
-        'ALRM', sub {
-          dbh->clone()->do("KILL QUERY ". dbh->{"mysql_thread_id"})
-            if driver_name eq 'mysql';
-          die '_timeout';
-        },
-        { mask=>['ALRM'] , safe=>1 }
-      );
+      my $h = set_sig_handler( 'ALRM', sub { die "_timeout\n"; } );
       alarm(5*60); # 15*60);
       $sth->execute($serviceid, $serviceid) or die $sth->errstr;
       alarm(0);
     };
     alarm(0);
-    if ( $@ =~ /^_timeout/ ) {
+    
+    if ( $@ && $@ eq "_timeout\n" ) {
       warn "search timed out; reconnecting and restarting\n";
+      dbh->clone()->do("KILL QUERY ". dbh->{"mysql_thread_id"})
+        if driver_name eq 'mysql';
       adminsuidsetup($user);
       next MAIN;
     } elsif ( $@ ) {
       die $@;
     }
 
-    warn "search executed; checking results" if $DEBUG;
+    warn "search executed; checking results\n" if $DEBUG;
 
     my $prev = 0;
     while ( my $row = $sth->fetchrow_arrayref ) {