Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > handling hanging database connections: timeout in perl

Reply
Thread Tools

handling hanging database connections: timeout in perl

 
 
daniel.crosby@gmx.de
Guest
Posts: n/a
 
      11-24-2006
The eval does not seem to be enough to provoke a timeout on a hanging
oracle connection i.e. where i get no response. I do not understand why
this does not work in this perl example.

foreach $l_db (keys %{ $G_ALL_DB{$l_host}}) {
($l_ars, $l_ars_sev)= split /\|/, $G_ALL_DB{$l_host}{$l_db};
$l_startdb=time(); # = now
$G_COUNT_DB_CONNECT++;
eval { ### TRY ###
$l_erg="";
$l_exe_ok=0;
use DBI;
$ENV{ORACLE_HOME}=$G_CONF{DBHOME};
$SIG{ALRM} = sub {&ConnectTimeOut ($l_host, $l_db, $l_ars,
$l_ars_sev, $l_erg) };

alarm $G_CONF{TIMEOUT_DB_CONNECT};

$l_cstr="DBI:Oracle:$l_db";
$l_dbh = DBI->connect($l_cstr, $G_CONF{TEST_USER},
$G_CONF{TEST_PASS}, { PrintError=>0, RaiseError=>0, AutoCommit=>1 });

if ($l_dbh) {

if ($l_results= $l_dbh->prepare ($G_SEL_TIV_CONN_CHECK )) {
$l_results->execute;
$l_exe_ok=1;

# fetch rows
while (@l_row = $l_results->fetchrow_array) {
$l_erg=$l_row[0];
if ( $l_erg !~ /XOK/ ) {
$l_msg="$l_db Result doesn't match XOK";
@l_errstr=();
&ConnectFailed ($l_host, $l_db, $l_ars, $l_ars_sev, $l_msg,
@l_errstr);
} else {
&Logging (3, $I, $l_db, "Connect success. DB = $l_db");
$G_RESULTS_CONNECT{$l_db}="connect_succeeded";
}
}
}

$l_dbh->disconnect or &warn ("Can not close DB $l_db,
$DBI::errstr\n");
}
alarm 0;
};
if ($@) { ### CATCH exception ###
$l_err = $@;
$l_err =~ s/\n/ /g;
$l_msg = "$l_db Exception connecting : $l_err";
# Check for errors to ignore, alert the Rest
@l_errstr = grep $DBI::errstr =~ m/$_/, keys
%G_IGNORE_ORACLE_ERRORS;
&ConnectFailed ($l_host, $l_db, $l_ars, $l_ars_sev, $l_msg,
@l_errstr );

# &Logging (0, $A, "exception", $l_msg);
}
if ( $l_exe_ok != 1 ) {
$l_msg="$l_db Connect failure : $DBI::errstr";
# Check for errors to ignore, alert the Rest
@l_errstr = grep $DBI::errstr =~ m/$_/, keys
%G_IGNORE_ORACLE_ERRORS;
&ConnectFailed ($l_host, $l_db, $l_ars, $l_ars_sev, $l_msg,
@l_errstr );
}

 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      11-24-2006
wrote:
> The eval does not seem to be enough to provoke a timeout on a hanging
> oracle connection i.e. where i get no response. I do not understand why
> this does not work in this perl example.


Your code is pretty much unreadable. You should produce a reduced example


> $SIG{ALRM} = sub {&ConnectTimeOut
> ($l_host, $l_db, $l_ars, $l_ars_sev, $l_erg) };


You haven't shown us what ConnectTimeOut does. That is pretty important if
we are to help you.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
 
 
 
daniel.crosby@gmx.de
Guest
Posts: n/a
 
      11-26-2006
The script contains also the following information, i cannot see why
the timeout would not be used when specified, some database connections
just hang and do not timeout as they should per script.

sub ConnectTimeOut {
# ================================================== ==============
my ($p_host, $p_db, $p_ars, $p_sev, $p_erg)=@_;
my @l_errstr = grep $DBI::errstr =~ m/$_/, keys
%G_IGNORE_ORACLE_ERRORS;
$l_msg = "$p_db Timeout $G_CONF{TIMEOUT_DB_CONNECT} sec
occurred conn
ecting $p_db";
&Logging (0, $A, "timeout", $l_msg);

 
Reply With Quote
 
xhoster@gmail.com
Guest
Posts: n/a
 
      11-26-2006
wrote:
> The script contains also the following information, i cannot see why
> the timeout would not be used when specified,


Heck, and I can't even see why that code would even compile, much less
why you would expect it to time anything out.


> some database connections
> just hang and do not timeout as they should per script.
>
> sub ConnectTimeOut {
> # ================================================== ==============
> my ($p_host, $p_db, $p_ars, $p_sev, $p_erg)=@_;
> my @l_errstr = grep $DBI::errstr =~ m/$_/, keys
> %G_IGNORE_ORACLE_ERRORS;
> $l_msg = "$p_db Timeout $G_CONF{TIMEOUT_DB_CONNECT} sec
> occurred conn
> ecting $p_db";
> &Logging (0, $A, "timeout", $l_msg);


Where is the die statement? Where is the closing bracket?

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      11-27-2006
<> wrote:

> &Logging (0, $A, "timeout", $l_msg);

^
^

Why do you choose to circumvent prototypes?


--
Tad McClellan SGML consulting
Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Database Database Database Database scott93727@gmail.com Computer Information 0 09-27-2012 02:43 AM
DataBase DataBase DataBase DataBase scott93727@gmail.com Computer Information 0 09-26-2012 09:40 AM
ASP.NET page doesn't timeout when hanging on database call Marcin Belczewski ASP .Net 2 10-28-2005 07:54 AM
Perl debug hanging jennykelly@gmail.com Perl Misc 2 09-06-2005 08:41 PM
Timeout::timeout and Socket timeout Mark Probert Ruby 1 10-06-2004 09:30 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57