handling hanging database connections: timeout in perl

Discussion in 'Perl Misc' started by daniel.crosby@gmx.de, Nov 24, 2006.

  1. Guest

    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 );
    }
    , Nov 24, 2006
    #1
    1. Advertising

  2. Guest

    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
    , Nov 24, 2006
    #2
    1. Advertising

  3. Guest

    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);
    , Nov 26, 2006
    #3
  4. Guest

    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
    , Nov 26, 2006
    #4
  5. <> wrote:

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

    ^
    ^

    Why do you choose to circumvent prototypes?


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Nov 27, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marcin Belczewski
    Replies:
    2
    Views:
    488
    Marcin Belczewski
    Oct 28, 2005
  2. jobs
    Replies:
    1
    Views:
    5,180
    bruce barker
    Nov 10, 2007
  3. jobs
    Replies:
    2
    Views:
    873
  4. Mark Probert

    Timeout::timeout and Socket timeout

    Mark Probert, Oct 6, 2004, in forum: Ruby
    Replies:
    1
    Views:
    1,267
    Brian Candler
    Oct 6, 2004
  5. Perl debug hanging

    , Sep 6, 2005, in forum: Perl Misc
    Replies:
    2
    Views:
    103
    John W. Krahn
    Sep 6, 2005
Loading...

Share This Page