Added content connect timeout
authorBill Erickson <berick@esilibrary.com>
Mon, 24 Sep 2012 16:50:47 +0000 (12:50 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Wed, 3 Oct 2012 16:39:32 +0000 (12:39 -0400)
Make tpac server-side added content lookups exit after a brief timeout
when the apache module is unable to open a connection to its own
top-level hostname (the virtualhost, apache->hostname).

As noted in the code comments, even though we are using Net::Server::NB
(non-blocking), it's only non-blocking in the sense of content
retrieval, not in how it calls connect() under the covers.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Michael Peters <mrpeters@library.in.gov>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm

index 3ccbe64..6f15dab 100644 (file)
@@ -441,10 +441,20 @@ sub added_content_stage1 {
         if ($key) {
             $logger->debug("tpac: starting added content request for $key => $type");
 
-            my $req = Net::HTTP::NB->new(Host => $self->apache->hostname);
+            # Net::HTTP::NB is non-blocking /after/ the initial connect()
+            # Passing Timeout=>1 ensures we wait no longer than 1 second to 
+            # connect to the local Evergreen instance (i.e. ourself).  
+            # Connecting to oneself should either be very fast (normal) 
+            # or very slow (routing problems).
+            my $req = Net::HTTP::NB->new(
+                Host => $self->apache->hostname,
+                Timeout => 1
+            );
 
             if (!$req) {
-                $logger->warn("Unable to fetch added content from " . $self->apache->hostname . ": $@");
+                $logger->warn("Unable to connect to " . 
+                    $self->apache->hostname . 
+                    " for added content lookup for $key: $@");
                 next;
             }