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