dhj74 has asked for the wisdom of the Perl Monks concerning the following question:

The I'm using the following code to attempt to open a file handle to an oracle database and to handle a failure of the attempt in a somewhat graceful manner:

BEGIN { my $need= '/local/src/local.perl/oracle/instantclient_10_2'; my $ld= $ENV{LD_LIBRARY_PATH}; if( ! $ld ) { $ENV{LD_LIBRARY_PATH}= $need; } elsif( $ld !~ m#(^|:)\Q$need\E(:|$)# ) { $ENV{LD_LIBRARY_PATH} .= ':' . $need; } else { $need= ""; } if( $need ) { exec 'env', $^X, $0, @ARGV; } } use DBI; use DBD::Oracle; use Sys::SigAction qw( set_sig_handler ); my $dbh; my $host = "some.where.else"; my $sid = "FAKE"; my $user = 'faker'; my $passwd = 'evenmorefaker'; my $thissrv = `hostname`; $start = time; $elapsed = time; while (1) { last if( ($elapsed - $start) > 14400 ); # stop after 4hrs of tryin +g sleep(2); eval { my $h = set_sig_handler( 'ALRM' ,sub { die "connect failed" ;} + ); alarm(2); #implement 2 second time out $dbh = DBI->connect("dbi:Oracle:host=$host;sid=$sid", $user, $ +passwd); alarm(0); }; #original signal handler restored here when $h goes out of scop +e alarm(0); if ( $@ ) { # The attempt to connect to db has failed chomp($@); # just for debugging print "FAILED:$@:$elapsed\n"; $elapsed = time; next; } # # reaching here shows database is now accessable # $elapsed = time; last; # exit the polling loop } #just for debuging print "Pretending to bring services up"

Now the code works ok but when it finishes its run it spits out:

root@somewhere# ./test.pl Pretending to bring services up Out of memory! Callback called exit. END failed--call queue aborted. root@somewhere #

The problem seems to stem from using Sys::SigAction. Any suggestions about why I'm getting 'Out of memory!' errors?

dhj...

Replies are listed 'Best First'.
Re: "Out of memory!" and Sys::SigAction
by sgt (Deacon) on Oct 04, 2006 at 22:35 UTC

    does it work using $SIG(ALARM} = sub { die ...}; instead of Sys::Sigaction?

Re: "Out of memory!" and Sys::SigAction
by dhj74 (Initiate) on Oct 04, 2006 at 22:04 UTC

    FYI

    I'm running this script on a Solaris 10 box with perl v5.8.4 built for sun4-solaris-64int

Re: "Out of memory!" and Sys::SigAction
by jbert (Priest) on Oct 05, 2006 at 09:31 UTC
    No idea what's going on, but you could try using 'timeout_call' from Sys::Sigaction, does what you want and might wrap things differently.

      I tried your suggestion but unfortuantely it still produces the "Out of memory!" error :'(

      Much googling and trolling of newsgroups really hasn't shed much light on what's goin on here.

        I don't know if it is a good idea in your context, but as of perl 5.8.1 I think you can go back to unsafe signals by specifying PERL_SIGNALS=unsafe in the environment. Carpe typor and all that.