From: Daniel Berger Date: 2003-04-09T01:48:33+09:00 Subject: Re: Problem with timeout for DBI on Solaris Brian Candler wrote: > > On Wed, Apr 09, 2003 at 01:10:46AM +0900, Daniel Berger wrote: > > As a test, we took down one of our test database machines and tried to > > connect to it. The problem is that, on Solaris boxes, it seems to > > ignore the 'timeout' that we've wrapped the connection in. Here's the > > code: > ... > > timeout(3){ > > dbh = DBI.connect(dsn,user,passwd) > > } > > I think that the problem is that once DBI.connect has committed to calling > the Oracle C library, it won't come back until it has finished one way or > the other. In other words, it doesn't play nicely with Ruby's cooperative > threading. If a SIGALRM is raised after 3 seconds, Ruby just takes a note of > it and lets the library call complete before taking action. > > For Oracle, you can try using the ruby-oci8 library from RAA which supports > non-blocking queries (although I don't know if it supports non-blocking > connect). It comes with its own DBD which you have to install manually into > /usr/local/lib/ruby/site_ruby/1.6/DBD/OCI8/OCI8.rb I'll give it a shot. FYI, I tried a similar script with Perl: # Begin code use strict; use DBI; my $dbh; eval{ alarm(5); $dbh = DBI->connect("dbi:Oracle:$db",$login,$passwd,{ RaiseError => 1, PrintError => 1}); alarm(0); }; if($@){ print "Error: $@\n"; exit; } # End code This was the result: "Error: DBI->connect(db) failed: ORA-12560: TNS:protocol adapter error (DBD ERROR: OCIServerAttach)" So, it looks like it was a driver issue (?). Perl's driver seems to be non-blocking by default, which I think would be nice. Thanks for the info. Regards, Dan