handling hanging database connections: timeout in perl

D

daniel.crosby

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 );
}
 
X

xhoster

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
 
D

daniel.crosby

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);
 
X

xhoster

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top